Skip to content

Instantly share code, notes, and snippets.

@J7mbo
Created August 8, 2018 14:37
Show Gist options
  • Save J7mbo/135484899c23ca8a1ef5ff97e1541c8a to your computer and use it in GitHub Desktop.
Save J7mbo/135484899c23ca8a1ef5ff97e1541c8a to your computer and use it in GitHub Desktop.
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