ARCHIVED |
---|
If you are interested in weather data, try: |
United States: NationalWeatherService-Swift |
Canada: MeteorologicalServiceOfCanada-Swift |
A free and open-source weather API, powered by government data.
Platform | CI |
---|---|
Apple | |
Linux (Ubuntu & Amazon) |
Data sources can be easily incorporated by conforming to WeatherProvider
. Failing data sources are handled gracefully.
It is possible to use this library in your app to directly query the weather source. This is useful if you do not want to pay for a server . However, you can also use this library on a server if you prefer more control. See WeatherProvider-Server.
Instead of providing an accurate coordinate, you may provide a location in the form of a Geohash, which has varying degrees of accuracy depending on your configuration.
Use Swift Package Manager.
YOU NEED TO DO SOME CONFIGURATION BEFORE YOU CAN USE WEATHER PROVIDER. SEE CONFIGURATION.
As of 0.3.0, this package only supports the National Weather Service and getting the current weather condition.
let weatherProvider = WeatherProvider()
weatherProvider.getCurrentConditions(for: Coordinates(latitude: 47.6174, latitude: -122.2017)) { result in
switch result {
case .success(let conditions): print(conditions)
case .failure(let error): print(error)
}
}
If you prefer, you can use a geohash instead of exact coordinates. Note that using a geohash will use the center coordinate of that geohash, so you'll want to be careful of how precise of a hash you want to use.
let geohash = Geohash(coordinates: (47.6174, -122.2017), precision: 5) // "c23ng"
weatherProvider.getCurrentConditions(for: geohash) { result in // results in (47.61474609375, -122.18994140625)
switch result {
case .success(let conditions): print(conditions)
case .failure(let error): print(error)
}
}
This project is currently unstable, subject to major API changes. As of now, a lot of the terminology is based off the United States National Weather Services definitions. I am looking to generalize the model as I continue to incorporate more sources.
- This Swift library is MIT License.
- Data source licenses may vary, but in general should be public-domain.