![](/img/trans.png)
[英]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.