Skip to content

Instantly share code, notes, and snippets.

@CollectiveHealth-gists
Created August 8, 2017 18:48
Show Gist options
  • Save CollectiveHealth-gists/ce686f6674584f29e9c15719611af901 to your computer and use it in GitHub Desktop.
Save CollectiveHealth-gists/ce686f6674584f29e9c15719611af901 to your computer and use it in GitHub Desktop.
Swift Download Image from Url
// 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