2015-11-26 60 views
0

我有一个函数将JSON结果设置为一个NSDictionary。然后它使用这个值来调用其他一些函数。我正在使用Alamofire,并且自从我在Swift 1中编写这个应用程序以来,有些内容已经改变,这给我带来了错误。Alamofire库Void不能转换为Response <AnyObject,NSError> - >无效

下面是函数:

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' 

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

请帮忙! :)

回答

0

试试这个:

 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) 
      } 
相关问题