Ios 自定义Alamofire响应函数中的编译器错误
我正在尝试使用Argo为Alamofire实现一个通用的Ios 自定义Alamofire响应函数中的编译器错误,ios,swift,alamofire,Ios,Swift,Alamofire,我正在尝试使用Argo为Alamofire实现一个通用的responseObject函数。不幸的是,我遇到了一个持续的编译器错误: error: missing argument for parameter #2 in call APIManager.manager.request(APIRouter.Login(username: usernameTextField.text, password: passwordTextField.text)).responseObject
responseObject
函数。不幸的是,我遇到了一个持续的编译器错误:
error: missing argument for parameter #2 in call
APIManager.manager.request(APIRouter.Login(username: usernameTextField.text, password: passwordTextField.text)).responseObject { (object, error) -> Void in
我理解这个错误通常意味着元组,所以我猜测代码中的某些内容被误解为元组,但我不知道是什么。这是我的responseObject
函数:
func responseObject<T: Decodable where T == T.DecodedType>(completionHandler: (T?, NSError?) -> Void) -> Self {
return responseJSON(options: .AllowFragments) { (request, response, JSON, error) in
// TODO: Complete error handling.
var responseObject: T?
if let JSON: AnyObject = JSON,
let response: Response = decode(JSON) where response.status == "0" {
responseObject = decode(JSON)
}
completionHandler(responseObject, error)
}
}
func-responseObject(completionHandler:(T?,NSError?)->Void)->Self{
在中返回responseJSON(选项:.AllowFragments){(请求、响应、JSON、错误)
//TODO:完成错误处理。
var响应对象:T?
如果让JSON:AnyObject=JSON,
let response:response=decode(JSON),其中response.status==“0”{
responseObject=decode(JSON)
}
completionHandler(响应对象,错误)
}
}
我的请求代码和路由器工作得很好,正是添加了这个
responseObject
函数才打破了这一切。结果表明,您需要为带到闭包中的变量提供一个显式类型,并使用一个通用返回类型。因此,与中的(object,error)不同,我需要(object:SpecificType?,error)
有时错误会显示为无法使用类型为“(((,)->Void)”的参数列表调用“responseObject”
,这似乎是闭包的问题,但签名匹配。