Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of unresolved identifier 'GMSPlacesClient' in xcode 7.3.1

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)
        }
}

I used this method to searching address in google map. But Use of unresolved identifier 'GMSPlacesClient' error found. How could I resolve this?

like image 439
Shahbaz Akram Avatar asked Aug 05 '16 06:08

Shahbaz Akram


People also ask

How do I get rid of the “unresolved” error in Xcode?

Try reducing the "unresolved" source file down to the bare minimum, cleaning and building. Once it builds successfully add all the complexity back to your class. This has made it go away for me when re-starting Xcode did not work.

What does'use of unresolved identifier'mean in Swift?

'Use of Unresolved Identifier' in Swift my also happen when you forgot to import a library. For example I have the error: Show activity on this post. Sometimes the compiler gets confused about the syntax in your class. This happens a lot if you paste in source from somewhere else.

Why does Xcode make my code so complicated?

This happens a lot if you paste in source from somewhere else. Try reducing the "unresolved" source file down to the bare minimum, cleaning and building. Once it builds successfully add all the complexity back to your class. This has made it go away for me when re-starting Xcode did not work.


2 Answers

If use cocoapod, you need add pod 'GooglePlaces'. And import GooglePlaces.

like image 63
Valeriy Avatar answered Nov 11 '22 22:11

Valeriy


Use of unresolved identifier 'GMSPlacesClient' error probably occurs when your new class has a different Target(s) from the other one. It is stated in this thread that it might have a testing target and the other doesn't. For this case, you have to include all of your classes in the testing target or none of them.

This blog also gives possible solution for error, “Use of unresolved identifier”. Change the access control on your class to public. Additionally, mark any methods you intend to test with public also. Try also to add the class(es) you want to be able to write unit tests for to the tests target.

You can also check this related SO question. Hope this helps!

like image 30
abielita Avatar answered Nov 11 '22 20:11

abielita