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 updateTo 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.currentTempWeatherItem can be accessed from instances of ForecastItem. Here is example:
forecast.main.celsius.currentTempPlease 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. |
