Skip to content

Instantly share code, notes, and snippets.

@ryanwilson
Created February 26, 2016 02:30
Show Gist options
  • Save ryanwilson/6074f25031e7b737cb49 to your computer and use it in GitHub Desktop.
Save ryanwilson/6074f25031e7b737cb49 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let url = NSURL(string: "http://jsonplaceholder.typicode.com/users/3")
let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithURL(url!, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
let response = response as! NSHTTPURLResponse
switch response.statusCode {
case 200:
print("------------")
print(response)
print("------------")
print(NSString(data: data!, encoding: NSUTF8StringEncoding))
print("------------")
case 400..<500:
print("Something went wrong, error code: \(response.statusCode)")
default:
print("Other code: \(response.statusCode)")
}
XCPlaygroundPage.currentPage.finishExecution()
})
dataTask.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment