Last active
November 30, 2020 00:35
-
-
Save atierian/49b6134bb156fecfcec85fc8f2fc5dd4 to your computer and use it in GitHub Desktop.
Simple extension on UIImageView to display UIImage 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 | |
guard let image = url | |
.flatMap({ try? Data(contentsOf: $0) }) | |
.flatMap({ UIImage(data: $0) }) | |
else { return } | |
DispatchQueue.main.async { | |
self?.image = image | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment