Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift4 Error Cannot convert value of type '(_) -> Void' to expected argument type '(_) -> _'

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?

like image 477
nhuluseda Avatar asked Dec 04 '22 20:12

nhuluseda


2 Answers

Use .done Instead of using .then it will work.

like image 147
Sandeep Vishwakarma Avatar answered May 20 '23 05:05

Sandeep Vishwakarma


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)
            }
        })
    }
}
like image 38
Kejsi Struga Avatar answered May 20 '23 04:05

Kejsi Struga