Last active
October 26, 2015 18:32
-
-
Save adamdahan/c772d7731d4ebe733e17 to your computer and use it in GitHub Desktop.
Async image download swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var image: UIImage? | |
var imageURL = "Some url" | |
if let url = NSURL(string: imageURL) { | |
let request: NSURLRequest = NSURLRequest(URL: url) | |
let mainQueue = NSOperationQueue.mainQueue() | |
NSURLConnection.sendAsynchronousRequest(request, queue: mainQueue, completionHandler: { (response, data, error) -> Void in | |
if error == nil { | |
let image = UIImage(data: data) | |
dispatch_async(dispatch_get_main_queue(), { | |
// Update image | |
}) | |
} | |
else { | |
println("Error: \(error.localizedDescription)") | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment