Skip to content

Instantly share code, notes, and snippets.

@Ajimi
Created June 28, 2020 14:11
Show Gist options
  • Save Ajimi/5466b046e79a22257d724692b23f8c75 to your computer and use it in GitHub Desktop.
Save Ajimi/5466b046e79a22257d724692b23f8c75 to your computer and use it in GitHub Desktop.
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