O'Reilly logo

Swift by Example by Giordano Scalzo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connecting to the server

This class uses Alamofire, the Swift equivalent of AFNetworking, the most used third-party library to help handle network communications in iOS. This class also uses SwiftyJson, which eliminates the problem of the nested checks for optionals 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 { func retrieveCurrentWeatherAtLat(lat: CLLocationDegrees, lon: CLLocationDegrees, block: (weatherCondition: WeatherCondition) -> Void) { } func retrieveHourlyForecastAtLat(lat: CLLocationDegrees, lon: CLLocationDegrees, block: (weatherConditions: Array<WeatherCondition>) -> Void) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required