Last active
June 14, 2022 07:39
-
-
Save saud978/0bfdd63b47d682c1cb2c39ebbbaed1c4 to your computer and use it in GitHub Desktop.
Swift extension to load image from URL to UIImageView
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 loadFrom(URLAddress: String) { | |
guard let url = URL(string: URLAddress) else { | |
return | |
} | |
DispatchQueue.main.async { [weak self] in | |
if let imageData = try? Data(contentsOf: url) { | |
if let loadedImage = UIImage(data: imageData) { | |
self?.image = loadedImage | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment