Created
February 26, 2016 02:30
-
-
Save ryanwilson/6074f25031e7b737cb49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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