2015-11-26 61 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) 
      } 
相關問題