Created
June 25, 2016 17:20
-
-
Save rayfix/d9d77bdce7a9b1301b827194393ac89e to your computer and use it in GitHub Desktop.
A simple network request using NSURLSession
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
| import UIKit | |
| import XCPlayground | |
| var str = "Hello, playground" | |
| XCPlaygroundPage.currentPage.needsIndefiniteExecution = true | |
| let config = NSURLSessionConfiguration.defaultSessionConfiguration() | |
| config.HTTPAdditionalHeaders = ["foo": "bar"] | |
| let session = NSURLSession(configuration: config) | |
| let url = NSURL(string: "http://www.google.com/")! | |
| let task = session.dataTaskWithURL(url) { data, response, error in | |
| if let data = data { | |
| let string = NSString(data: data, encoding: NSASCIIStringEncoding) | |
| print("Hello \(data) \(string)") | |
| } | |
| } | |
| task.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment