Book Image

Swift by Example

By : Giordano Scalzo
Book Image

Swift by Example

By: Giordano Scalzo

Overview of this book

Table of Contents (15 chapters)

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) {
    }
    
    func retrieveDailyForecastAtLat(lat: Double,
        lon: Double,
        dayCnt: Int,
        block: (weatherConditions: Array<WeatherCondition>) -> Void) {
    }
 ...