Weather Underground Swift API wrapper.

What's New



Fix few typos.


Swift 5.1 Swift PM Compatible Swift

This package is a simple wrapper around the Weather Underground API. It provides a quick access to the current value of the Personal Weather Station (PWS), as well as hourly, and daily history. The features may be extended in the future if there is an interest (PR are welcome!).

The documentation is coming directly from the Weather Underground API.

The wrapper is a pure Swift wrapper, with codable, and use Foundation for the networking. There is no dependencies!

To use the API, simple set the API key from Weather Underground, and specify your station like that:

WeatherGround.measure.apiKey = "1234567890af"
WeatherGround.measure.station = "station_id"

If you want to retrieve the current values for the station:

WeatherGround.measure.current(){ values in 
    guard case .success(let observation) = values else {
        print("Cannot retrieve the current values")
    print("The weather is: \(observation)")

If you need to retrieve historical values, you can use one of hourly, daily or all. hourly and all returns a list of observations, whereas daily returns the daily average.

WeatherGround.measure.hourly(for: Date()){ history in 
    guard case .success(let observations) = history else {
        print("Unable to retrieve the observations.")
    print("The weather for \(Date()) was \(observations)")

The 5 day forecast is also available through forecast. It doesn't required a station value, only the apiKey.

WeatherGround.measure.forecast(for: Location.geo(latitude: 33.74, longitude: -84.39)){ fiveDay in
    guard case .success(let forecast) = fiveDay else {
        print("Unable to retrieve the forecast")
    print("5 day forecast:")
    for (day, narrative) in zip(forecast.dayOfWeek, forecast.narrative) {
        print("\(day): \(narrative)")
    if let daypart = forecast.daypart.first {
        print("5 day forecast per day:")
        for (day, narrative) in zip(daypart.daypartName, daypart.narrative) {
            if let day = day, let narrative = narrative {
                print("\(day): \(narrative)")

You can also retrieve the wind direction, intensity and narrative, as well as the temperature, rain, snow, moon phase, sunrise and sunset, thunder and precipitation chance, humidity and the icons id (list and id available here)


  • Swift Tools 5.1.0
View More Packages from this Author


  • None
Last updated: Wed May 24 2023 12:27:43 GMT-0500 (GMT-05:00)