Skip to content

Instantly share code, notes, and snippets.

@jeksys
Created May 11, 2017 22:22
Show Gist options
  • Save jeksys/75f4624885dbbec35f271bb241f94be8 to your computer and use it in GitHub Desktop.
Save jeksys/75f4624885dbbec35f271bb241f94be8 to your computer and use it in GitHub Desktop.
extension UIImageView {
func setImage(from url: URL, withPlaceholder placeholder: UIImage? = nil) {
self.image = placeholder
URLSession.shared.dataTask(with: url) { (data, _, _)
if let data = data {
let image = UIImage(data: data)
DispatchQueue.main.async {
self.image = image
}
}
}.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment