Search code examples
iosswift3google-places-apigmsautocomplete

GMSAutocompletePrediction prediction.attributedFullText not give nsmutablestring in swift 3.0


I use GMSAutocompleteFetcher in my swift project to search places. Here I install 'GooglePlaces''GooglePlacePicker' 'GoogleMaps' with pods and write all things as in link https://developers.google.com/places/ios-api/autocomplete#use_the_fetcher but after write in textFieldDidChange I got result according to it in delegate method :

func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
        let resultsStr = NSMutableString()
        for prediction in predictions {
            resultsStr.appendFormat("%@\n", prediction.attributedFullText)

        }

but in resultsStr got value :

 Ca{
    GMSAutocompleteMatch = "<GMSAutocompleteMatchFragment: 0x608000223940>";
}lifornia{
}

It should be "California"


Solution

  • Swift 3.0 code..

    Your prediction.attributedFullText attributed text to convert first in the string and then you get string type result.

       func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
        let resultsStr = NSMutableString()
        for prediction in predictions {
            resultsStr.appendFormat("%@\n", prediction.attributedPrimaryText.string)
        }
        print(resultsStr) //California
        }