Created
June 28, 2020 14:11
-
-
Save Ajimi/5466b046e79a22257d724692b23f8c75 to your computer and use it in GitHub Desktop.
This file contains 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 UIImage { | |
public static func loadFrom(url: URL, completion: @escaping (_ image: UIImage?) -> ()) { | |
DispatchQueue.global().async { | |
if let data = try? Data(contentsOf: url) { | |
DispatchQueue.main.async { | |
completion(UIImage(data: data)) | |
} | |
} else { | |
DispatchQueue.main.async { | |
completion(nil) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment