Skip to content

Instantly share code, notes, and snippets.

@olbrichj
Created March 21, 2018 11:12
Show Gist options
  • Save olbrichj/1b039c07f945029080e1760538a0ee17 to your computer and use it in GitHub Desktop.
Save olbrichj/1b039c07f945029080e1760538a0ee17 to your computer and use it in GitHub Desktop.
func fetch(url: URL) -> Promise<Data> {
return Promise { seal in
URLSession.shared.dataTask(with: url!) { data, _, error in
seal.resolve(data, error)
}.resume()
}
}
fetch(url: <backendURL>).then { data in
return JSONParsePromise(data) // we skip the wrapping of JSONParsing
}.then { imageurl in
return fetch(url: imageurl)
}.then { data in
imageView.image = UIImage(data: data)
}.catch { error in
// in case we have an error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment