Skip to content

Instantly share code, notes, and snippets.

@sean7218
Created August 13, 2018 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean7218/5eb15be61033e67025deaf2287dc460c to your computer and use it in GitHub Desktop.
Save sean7218/5eb15be61033e67025deaf2287dc460c to your computer and use it in GitHub Desktop.
load the image from url
extension UIImageView {
func load(url: URL) {
DispatchQueue.global().async { [weak self] in
if let data = try? Data(contentsOf: url) {
if let image = UIImage(data: data) {
DispatchQueue.main.async {
self?.image = image
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment