Reputation: 73
I am having issues compiling my app which I created in Swift 1 with Alamofire. The issue occurs at the following code:
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
}
}
The error given says:
Contextual type for closure argument list expects 1 argument, but 4 were specified
I have tried the solution from here but I can't get it to work without errors. Please help!
Upvotes: 1
Views: 889
Reputation: 267
Code should look like this
let _requestURL1 = Alamofire.request(.GET,dataSourceURL!)
_requestURL1.responseJSON { response in
let json = JSON(response.data!)
let token = json["token"].string
response(token: token)
}
As in the other post described, in Swift 2 the .responseJSON changed from 4 arguments to only 1
Upvotes: 1