Sunil M.
Sunil M.

Reputation: 564

Generic Parameter cannot be inferred in Closure

Right now i am trying to create a network layer class on the AlamoFire and AlamofireObjectMapper library. I have created one method for get request here is the following code

func getRequest<T: BaseMappable>(_ url : String,
                                 success: @escaping (DataResponse<T>) -> Void,
                                 failure: @escaping (Error) -> Void) -> Void {

    self.request(url, method: .get).responseObject{ (response : DataResponse<T>) in

        success(response as DataResponse<T>)
    }        
}

I have imported following library in the project

import Alamofire
import AlamofireObjectMapper
import ObjectMapper

Here is the Error which i am getting while trying to the method in the ViewController

enter image description here

Thanks in Advance for you support

Upvotes: 0

Views: 383

Answers (1)

Alistra
Alistra

Reputation: 5195

Try changing it to (response: DataResponse <Country>) in the block argument.

This is because your generic function doesn't know what type to use for the generic parameter and the type checker can't infer it. You help it by stating the type explicitly.

Upvotes: 3

Related Questions