[英]Swift - Closure cannot have keyword arguments Error In Xcode 7.3
[英]Alamofire closure arguments error when upgrading to swift 2
我在用Alamofire在Swift 1中创建的应用程序进行编译时遇到问题。 此问题发生在以下代码中:
func fetchApiData() {
print("called")
// I believe this is the problem code below.
let _requestURL1 = Alamofire.request(.GET,dataSourceURL!)
_requestURL1.responseJSON { (_requestUrl, _requestResponse, _objJSON1, error) -> Void in
if(_objJSON1 != nil)
{
let jsonResult1 = _objJSON1 as NSDictionary;
//let jsonResult2: NSDictionary! = NSJSONSerialization.JSONObjectWithData(data,
// options:NSJSONReadingOptions.MutableContainers, error: self.error) as NSDictionary
self.checkIP(jsonResult1)
self.checkGeo(jsonResult1)
//println(jsonResult1);
}
else{
return
}
}
给出的错误说明:
Contextual type for closure argument list expects 1 argument, but 4 were specified
我从这里尝试过该解决方案,但是没有错误我无法使其正常工作。 请帮忙!
代码应如下所示
let _requestURL1 = Alamofire.request(.GET,dataSourceURL!)
_requestURL1.responseJSON { response in
let json = JSON(response.data!)
let token = json["token"].string
response(token: token)
}
就像在另一篇文章中描述的那样,在Swift 2中,.responseJSON从4个参数更改为仅1个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.