Created
August 8, 2017 18:48
-
-
Save CollectiveHealth-gists/ce686f6674584f29e9c15719611af901 to your computer and use it in GitHub Desktop.
Swift Download Image from Url
This file contains hidden or 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
// create task to download image from url | |
let task = session.dataTask(with: imageURL) {(imageData, response, error) in | |
// check for image data | |
if let data = imageData { | |
// update UI on main thread | |
DispatchQueue.main.async { | |
self.imageView.image = UIImage(data: data) | |
// animate image alpha | |
UIView.animateWithDuration(0.3) { | |
self.imageView.alpha = 1 | |
} | |
} | |
} | |
} | |
task.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment