Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke Method with an argument list of type in swift

I have a function

func mapResponse<T:Mappable>(responseObject:Alamofire.Request, 
                   forRequest requestObject:RequestObject,
                              responseType:T,
                                completion:(AnyObject?,String?) -> Void) 
{
    responseObject.responseObject{(response: Response<T, NSError>) in
        if let error = response.result.error {
                       completion(nil,error.description)
                       return
                }
                else {
                    let value:T = response.result.value!
                    self.saveObject(value, forRequest: requestObject,completion: completion)
                }
            }
}

when i call it like

let model:Mappable = requestObject.responseModel
ResponseMapper.sharedInstance.mapResponse(request, 
                                           forRequest:requestObject,
                                         responseType:model,
                                           completion:completion)

where

struct RequestObject { 
    let requestName:RequestName 
    let parametersStructure:Array<ParameterKey>? 
    let inputParameters:Dictionary<Parameter,AnyObject>? 
    let requestType:RequestType 
    let requestUrl:String 
    let cachLevel:CachLevel 
    let responseModel:Mappable 
    let parameterEncoding:ParameterEncoding
}

it give me error:

"Cannot invoke 'Method' with an argument list"

while it's working fine as following

ResponseMapper.sharedInstance.mapResponse(request, 
                                        forRequest:requestObject,       
                                      responseType:CarModel(), 
                                        completion:completion)

where

Class CarModel: Mappable

where is the problem with first call

like image 542
AbBarjoud Avatar asked Apr 28 '16 06:04

AbBarjoud


1 Answers

requestObject.responseModel should conform to Mappable

 struct RequestObject<T where T:Mappable> {
    let responseModel:T
 }
like image 136
Ted Avatar answered Nov 02 '22 20:11

Ted