Skip to content

Instantly share code, notes, and snippets.

@dimebt
Created February 7, 2019 09:13
Show Gist options
  • Save dimebt/45d6952de7e58d63181bc638400231a0 to your computer and use it in GitHub Desktop.
Save dimebt/45d6952de7e58d63181bc638400231a0 to your computer and use it in GitHub Desktop.
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