Skip to content

Instantly share code, notes, and snippets.

@jad
Last active August 29, 2015 14:05
Show Gist options
  • Save jad/a748eecdfdbb6d99c64b to your computer and use it in GitHub Desktop.
Save jad/a748eecdfdbb6d99c64b to your computer and use it in GitHub Desktop.
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