Created
February 7, 2019 09:13
-
-
Save dimebt/45d6952de7e58d63181bc638400231a0 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
private func fetchJSON() -> Promise<[Photo]> { | |
return Promise { seal in | |
Alamofire.request(photosURL, method: .get).validate().responseData { (data) in | |
guard let data = data.result.value else { | |
seal.reject(PhotoError.ConvertToData) | |
return | |
} | |
guard let photos = try? JSONDecoder().decode([Photo].self, from: data) else { | |
seal.reject(PhotoError.PhotoDecoding) | |
return | |
} | |
seal.fulfill(photos) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment