简体   繁体   English

升级到Swift 2时Alamofire闭包参数错误

[英]Alamofire closure arguments error when upgrading to swift 2

I am having issues compiling my app which I created in Swift 1 with Alamofire. 我在用Alamofire在Swift 1中创建的应用程序进行编译时遇到问题。 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 就像在另一篇文章中描述的那样,在Swift 2中,.responseJSON从4个参数更改为仅1个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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