Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An extension of NSURLSession showcasing how its functionality could be wrapped in Futures
extension NSURLSession {
func fetch(url: String) -> Async<Result<(NSData, NSURLResponse), Error>> {
return Async { completion in
let task = self.dataTaskWithURL(NSURL(string: url)!, completionHandler: { (data, response, error) -> Void in
if let data = data, response = response {
completion(Result(value: (data, response)))
} else {
completion(Result(error: .LegacyError(error)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment