2016-08-05 65 views
4
func searchBar(searchBar: UISearchBar, 
    textDidChange searchText: String){ 

     let placesClient = GMSPlacesClient() 
     placesClient.autocompleteQuery(searchText, bounds: nil, filter: nil) { (results, error:NSError?) -> Void in 
      self.resultsArray.removeAll() 
      if results == nil { 
       return 
      } 
      for result in results!{ 
       if let result = result as? GMSAutocompletePrediction{ 
        self.resultsArray.append(result.attributedFullText.string) 
       } 
      } 
      self.searchResultController.reloadDataWithArray(self.resultsArray) 
     } 
} 

我用這種方法在谷歌地圖中搜索地址。但發現Use of unresolved identifier 'GMSPlacesClient'錯誤。我怎麼解決這個問題?在xcode中使用未解析的標識符'GMSPlacesClient'7.3.1

+0

你在此視圖控制器中導入谷歌地圖嗎? –

+0

import GoogleMaps是的,我輸入這個。 –

+0

基本上它通過cocoapds安裝Almofire之前工作正常。但是當我在豆莢中添加almofire時,我更新了豆莢這個錯誤occor。 –

回答

3

Use of unresolved identifier 'GMSPlacesClient'錯誤可能發生在您的新班級與另一班級有不同的目標時。在此thread中指出它可能有測試目標,另一個則沒有。對於這種情況,您必須將所有類都包含在測試目標中,或者不包含任何類。

blog也爲錯誤,「使用未解析的標識符」提供了可能的解決方案。將您的課程的訪問控制更改爲公開。此外,還可以用公共方式標記您打算測試的任何方法。也可以嘗試添加您希望能夠爲測試目標編寫單元測試的類。

您還可以檢查這個related SO question。希望這可以幫助!

+0

非常感謝。現在它工作正常。 –

8

如果使用cocoapod,則需要添加吊艙'GooglePlaces'。 並導入GooglePlaces。