简体   繁体   中英

Alamofire closure arguments error when upgrading to swift 2

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM