gpt4 book ai didi

ios - 无法使用 swift 类型的参数列表调用方法

转载 作者:搜寻专家 更新时间:2023-10-30 22:18:47 25 4
gpt4 key购买 nike

我有一个函数

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)
}
}
}

当我这样调用它的时候

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

在哪里

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
}

它给我错误:

"Cannot invoke 'Method' with an argument list"

虽然它工作正常,如下所示

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

在哪里

Class CarModel: Mappable

第一次调用的问题在哪里

最佳答案

requestObject.responseModel 应该符合Mappable

 struct RequestObject<T where T:Mappable> {
let responseModel:T
}

关于ios - 无法使用 swift 类型的参数列表调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36906493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com