Swift Package Index


Weather Underground Swift API wrapper.


  • The latest stable release is 0.0.3. Released 7 months ago.
  • The last commit to master was 7 months ago.

Swift Version Compatibility

  • 0.0.3 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.0.3 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

WeatherGround

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")
        return
    }
    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.")
        return
    }
    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")
        return
    }
    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)