2015-08-25 75 views
0

我配置restkit但我發現了錯誤,如如何解決這個錯誤

「不能調用getObjectAtPath」與參數列表.....

「不能與參數列表字符串類型的調用getObejectAtPath」

所以如何解決這個問題,我也想寫全局函數。

func fatchingData() { 
     var queryParams = "" 
     var path = "property_type/" 
     RKObjectManager.sharedManager().getObjectsAtPath(path, parameters: queryParams, success: { operation, mappingResult in 

      self.resultData = mappingResult.array() 


      }, 
      failure:{ operation, error in 
       println("error") 
      } 
     ) 
    } 

回答

0

queryParams有問題。您將其聲明爲String,但它必須是Dictionary

下面是它的示例代碼:從HERE

func loadVenues() { 
    let latLon = "37.33,-122.03" // approximate latLon of The Mothership (a.k.a Apple headquarters) 
    let queryParams = [ 
     "ll": latLon, 
     "client_id": kCLIENTID, 
     "client_secret": kCLIENTSECRET, 
     "categoryId": "4bf58dd8d48988d1e0931735", 
     "v" : "20140617" 
    ] 

    RKObjectManager.sharedManager().getObjectsAtPath("/v2/venues/search", parameters: queryParams, 
     success:{ operation, mappingResult in 
      self.venues = mappingResult.array() 
      self.tableView.reloadData() 
     }, 
     failure:{ operation, error in 
      NSLog("What do you mean by 'there is no coffee?': \(error!.localizedDescription)") 
     } 
    ) 
} 

參考。

希望它有幫助。