Skip to content

Instantly share code, notes, and snippets.

@jad

jad/perform-request

Last active Aug 29, 2015
Embed
What would you like to do?
func performRequest<A: Decodable>(request: NSURLRequest, callback: (Result<A>) -> ()) {
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, urlResponse, error in
let responseResult = Result(error, Response(data: data, urlResponse: urlResponse))
let result = responseResult >>> parseResponse
>>> decodeJSON
>>> A.decode
callback(result)
}
task.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment