Created
February 19, 2016 16:53
-
-
Save MosheBerman/464be029108d6e567296 to your computer and use it in GitHub Desktop.
A method that creates an NSURLSessionDataTask
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
func testTask() -> NSURLSessionDataTask? { | |
let components = NSURLComponents() | |
components.scheme = self.serverURLComponents.scheme | |
components.host = self.serverURLComponents.host | |
components.port = self.serverURLComponents.port | |
components.path = "/" | |
guard let url = components.URL else { | |
print("Failed to build URL from components. \(components)") | |
return nil | |
} | |
let request = NSURLRequest(URL: url) | |
let task = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()).dataTaskWithRequest(request, completionHandler: { (data : NSData?, response : NSURLResponse?, error : NSError?) -> Void in | |
/* Stuff happens in this callback. */ | |
}) | |
return task | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment