Using PromiseKit for API call in Swift 4:
let apiCall = ApiManager.shared.fetchActors()
apiCall.then { actors -> Void in
self.dataSourceArray = actors
self.tableView.reloadData()
}.catch { error -> Void in
}
I get this error:
Cannot convert value of type '() -> Void' to expected argument type '() -> _'
How do I solve this issue?
Use .done Instead of using .then it will work.
A solution:
func fetchActorsFromApi () -> Promise<[Actor]> {
return Promise<[Actor]> { seal in
return Alamofire.request(API_URL).validate().responseString(completionHandler: {
response in
switch (response.result) {
case .success(let responseString1):
print (responseString1) // should be converted into the modelclass
let actorResponse = ActorApiResponse(JSONString: "\(responseString1)")!
seal.fulfill(actorResponse.actors!)
case .failure(let error):
print (error)
seal.reject(error)
}
})
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With