我在使用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
我已尝试过here的解决方案,但我无法正常工作。请帮忙!
答案 0 :(得分:1)
代码应如下所示
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个