【问题标题】:Alamofire library Void is not convertible to Response<AnyObject, NSError> -> VoidAlamofire 库 Void 不能转换为 Response<AnyObject, NSError> -> Void
【发布时间】:2015-11-26 05:56:27
【问题描述】:

我有一个将 JSON 结果设置为 NSDictionary 的函数。然后它使用这个值来调用其他一些函数。我正在使用 Alamofire,并且由于我在 Swift 1 中编写了这个应用程序,所以这已经发生了一些变化,这给了我错误。

函数如下:

func fetchApiData() {


    // 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;
            self.checkIP(jsonResult1)
            self.checkGeo(jsonResult1)
        }
        else{
            return
        }
    }
        let _requestURL2 = Alamofire.request(.GET,self.dataSourceURL2!)
        _requestURL2.responseJSON { (_requestUrl, _requestResponse, _objJSON2, error) -> Void in
            if(_objJSON2 != nil)
            {
                let jsonResult2 = _objJSON2 as NSDictionary;
                self.checkDNS(jsonResult2)
                NSTimer.scheduledTimerWithTimeInterval(self.refreshFrequencyInt, target: self, selector: Selector("fetchApiData"), userInfo: nil, repeats: false)
            }
            else{
                return
            }
        }
    }

显然现在,这一行:

    _requestURL1.responseJSON { (_requestUrl, _requestResponse, _objJSON1, error) -> Void in

给我这个错误:

'(_, _, _, _) -> Void' is not convertible to 'Response<AnyObject, NSError> -> Void'

我已经尝试过解决此问题的方法,但我似乎无法让代码以与以前相同的方式工作。

请帮忙! :)

【问题讨论】:

    标签: swift alamofire


    【解决方案1】:

    试试这个:

           Alamofire.request(.GET, url)
            .responseJSON(completionHandler: {
            (JSON) -> Void in
                let JSONDictonary = JSON.result.value as! NSDictionary
               let photoInfos = (JSONDictonary.valueForKey("photos") as! [NSDictionary]).filter({
                    ($0["nsfw"] as! Bool) == false
                }).map{
                    PhotoInfo(id: $0["id"] as! Int, url: $0["image_url"] as! String)
                }
    

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      相关资源
      最近更新 更多