β οΈ Message from author: β οΈ
Guys thanks for your incredible support of that project. I see that it was useful for somebody and that makes me really happy.
Anyway, since last years I was mainly working as cloud-native applications developer and was using other technologies, I have no
plans to update this SDK at all.
So, feel free to fork it and make your own implementation of it. There is no need to create issues / requests here.
OpenWeatherMapKit is a small and simple framework written in Swift that gives you access to all features of the OpenWeatherMap service's APIs right in your iOS / macOS / watchOS/ tvOS application.
Just add following line to your Podfile:
pod 'OpenWeatherMapKit'
and run following command in your Terminal from project's root folder:
pod update
To normal working OpenWeatherMapKit must be initialized with your API token.
You can use following method to initialize OpenWeatherMapKit. Just replace [YOUR API TOKEN]
by your own API token which can be retrieved from https://home.openweathermap.org/api_keys:
OpenWeatherMapKit.initialize(withAppId: "[YOUR API TOKEN]")
Use OpenWeatherMapKit
class to retrieve weather data. It is a singleton and access to it's instance can be done through instance
variable.
You can retrieve weather data for specific city by it's name:
OpenWeatherMapKit.instance.currentWeather(forCity: "Samara") { (forecast, error) in
...
}
or event by city name and country code:
OpenWeatherMapKit.instance.currentWeather(forCity: "Samara", withCountryCode: "ru") { (forecast, error) in
...
}
You can retrieve weather data for specific geo location by it's coordinates:
OpenWeatherMapKit.instance.currentWeather(forCoordiante: (latitude: 53.2610313, longitude: 50.0579958)) { (forecast, error) in
...
}
You can retrieve weather data for next five days for specific city by it's name and country code:
OpenWeatherMapKit.instance.weatherForecastForFiveDays(forCity: "Samara", withCountryCode: "ru") { (forecast, error) in
...
}
or for specific geo location by it's coordinates:
OpenWeatherMapKit.instance.weatherForecastForFiveDays(forCoordiante: (latitude: 53.2610313, longitude: 50.0579958)) { (forecast, error) in
...
}
All operations for getting current weather data return special object of WeatherItem
type. WeatherItem
is a simple struct that contains temperature data on the board. Here are fields you can access on it:
/// Weather item's temperature values in Kelvin
public let kelvin: (currentTemp: Double, maxTemp: Double, minTemp: Double)
/// Weather item's temperature values in Celsius
public let celsius: (currentTemp: Double, maxTemp: Double, minTemp: Double)
/// Weather item's temperature values in Fahrenheit
public let fahrenheit: (currentTemp: Double, maxTemp: Double, minTemp: Double)
For example, if you want to get information on current weather in celsius you achieve that using following statement:
weatherItem.celsius.currentTemp
WeatherItem can be accessed from instances of ForecastItem
. Here is example:
forecast.main.celsius.currentTemp
Please find project's roadmap below:
Version | ETA | Feature |
---|---|---|
β v0.1 Β | January 2018 | Current weather forecast by city & geo coordinates + support of different units (Celsius, Kelvin, Fahrenheit) |
β v0.2 | April 2018 | Weather forecast for 5 days / 3 hour by city & geo coordinates. |
v0.3 | ??? | 16 day daily forecast by city & geo coordinates. |