OpenWeather One Call API,
“Make just one API call and get all your essential weather data for a specific location with our new OpenWeather One Call API.”
OWOneCall is a small Swift library to connect to the OpenWeather One Call API and retrieve the chosen weather data. Made easy to use with SwiftUI.
Provides for current, forecast and historical weather data through a single function call.
Usage
Weather data from OpenWeather One Call API is accessed through the use of a OWProvider, with a single function getWeather, eg:
let weatherProvider = OWProvider(apiKey: "your key")
@State var weather = OWResponse()
...
// using a binding
weatherProvider.getWeather(lat: 35.661991, lon: 139.762735, weather: $weather, options: OWOptions.current())
...
Text(weather.current?.weatherInfo() ?? "")
// or using the async style, eg with `.task {...}`
if let results = await weatherProvider.getWeather(lat: 35.661991, lon: 139.762735, options: OWOptions.dailyForecast(lang: lang)) {
weather = results
}
// or using the callback style, eg with `.onAppear {...}`
weatherProvider.getWeather(lat: 35.661991, lon: 139.762735, options: OWOptions.current()) { response in
if let theWeather = response {
self.weather = theWeather
}
}
SwiftUI OpenWeather One Call API library
OpenWeather One Call API, “Make just one API call and get all your essential weather data for a specific location with our new OpenWeather One Call API.”
OWOneCall is a small Swift library to connect to the OpenWeather One Call API and retrieve the chosen weather data. Made easy to use with SwiftUI.
Provides for current, forecast and historical weather data through a single function call.
Usage
Weather data from OpenWeather One Call API is accessed through the use of a OWProvider, with a single function getWeather, eg:
See the following for example uses:
OWOneCallExample
SwiftUI Weather App
Options
Options available:
Create an options object such as this, to retrieve the current weather data:
Additional convenience options to retrieve current and forecast weather data:
Additional convenience options to retrieve past historical weather data:
Use the lang options parameter to chose the language of the results, default “en”.
Installation
Include the files in the ./Sources/OWOneCall folder into your project or preferably use Swift Package Manager.
Swift Package Manager (SPM)
Create a Package.swift file for your project and add a dependency to:
Using Xcode
Then in your code:
References
Requirement
Requires a valid OpenWeather key, see:
License
MIT