Skip to content

Instantly share code, notes, and snippets.

@Nub
Created June 3, 2014 23:21
Show Gist options
  • Select an option

  • Save Nub/d39cb2f3ec235ce4eb66 to your computer and use it in GitHub Desktop.

Select an option

Save Nub/d39cb2f3ec235ce4eb66 to your computer and use it in GitHub Desktop.
func fetch(method: String, body: (NSString, NSData)!, completion: (NSData -> Void)) {
let request = self.request()
request.HTTPMethod = method
if body != nil {
let mime = body.0
let data = body.1
request.setValue(mime, forHTTPHeaderField: Networking.mimeHTTPHeaderField)
request.HTTPBody = data;
}
NSURLConnection.sendAsynchronousRequest(request, queue: Networking.operationQueue){(response: NSURLResponse!, data: NSData!, error: NSError!) in
completion(data)
}
}
func GET(completion: (NSData -> Void)) {
fetch("GET", body: nil, completion:completion)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment