Skip to content

Instantly share code, notes, and snippets.

@MosheBerman
Created February 19, 2016 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MosheBerman/464be029108d6e567296 to your computer and use it in GitHub Desktop.
Save MosheBerman/464be029108d6e567296 to your computer and use it in GitHub Desktop.
A method that creates an NSURLSessionDataTask
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