Connecting the ASAP app
After implementing the ASAP server, let's add the capability of communicating with a server to our ASAP app.
The products
The first gateway to implement is the one that handles the product, implementing the ProductGateway
protocol:
import Foundation class ServerProductGateway: ProductGateway { func getProducts(completion: (String) -> Void) { let session = NSURLSession.sharedSession() let task = session.dataTaskWithURL(EndPoint.Products.url()) { (data, response, error) -> Void in if error != nil { print(error!.localizedDescription) return } guard let data = data,let products = NSString(data: data,encoding: NSUTF8StringEncoding) as? String else { return } dispatch_async(dispatch_get_main_queue()) { completion(products) } } task.resume() ...
Get Swift 2 By Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.