Skip to content

Instantly share code, notes, and snippets.

@atierian
Last active November 30, 2020 00:35
Show Gist options
  • Save atierian/49b6134bb156fecfcec85fc8f2fc5dd4 to your computer and use it in GitHub Desktop.
Save atierian/49b6134bb156fecfcec85fc8f2fc5dd4 to your computer and use it in GitHub Desktop.
Simple extension on UIImageView to display UIImage from URL
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