Created
August 8, 2018 14:37
-
-
Save J7mbo/135484899c23ca8a1ef5ff97e1541c8a to your computer and use it in GitHub Desktop.
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
struct JsonDownloader | |
{ | |
public func downloadContentsOfUrl(url: URL, onComplete: @escaping (_ url: URL) -> UIImage) -> Void { | |
// This async call will be thrown onto a thread and then this function will return immediately | |
DispatchQueue.global(qos: .background).async { | |
let json = try! Data(contentsOf: url) | |
let jsonData = try! JSONSerialization.jsonObject(with: json, options: []) as! [String: Any] | |
onComplete(URL(string: jsonData["image_url"] as! String)!) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment