Created
March 21, 2018 11:26
-
-
Save olbrichj/cf0414a47bbd02276fe37701e69fd0f0 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
func fetch(url: URL) -> Promise<Data> { | |
return Promise { seal in | |
URLSession.shared.dataTask(with: url!) { data, _, error in | |
seal.resolve(data, error) | |
}.resume() | |
} | |
} | |
firstly { | |
UIApplication.shared.isNetworkActivityIndicatorVisible = true | |
return 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) | |
}.ensure { | |
UIApplication.shared.isNetworkActivityIndicatorVisible = false | |
}.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