Finally, we are ready to get the forecast data, and for that, we'll use a nice service called OpenWeatherMap, http://openweathermap.org, which offers a free tier as well.
To get access to the free tier, first of all we need to register to the site and then create a new API key, which will be passed as a parameter in every call to the server.
With this information, let's implement WeatherDatastore
.
This class uses Alamofire, the Swift equivalent of AFNetworking, the most used third-party library to help handle network communications in iOS. It also uses SwiftyJson, which eliminates the problem of nested checks for optional values during the decoding of JSON (short for JavaScript Object Notation, a lightweight data interchange format) data:
import Foundation import CoreLocation import Alamofire import SwiftyJSON class WeatherDatastore { let APIKey = "CREATE_API_KEY" func retrieveCurrentWeatherAtLat(lat: CLLocationDegrees, lon: CLLocationDegrees, block...