Created
August 13, 2018 18:20
-
-
Save sean7218/5eb15be61033e67025deaf2287dc460c to your computer and use it in GitHub Desktop.
load the 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
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