Created
May 11, 2017 22:22
-
-
Save jeksys/75f4624885dbbec35f271bb241f94be8 to your computer and use it in GitHub Desktop.
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
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