GMSAutocompletePrediction prediction.attributedFullText 在 swift 3.0 中不提供 nsmutablestring

GMSAutocompletePrediction prediction.attributedFullText not give nsmutablestring in swift 3.0

我在 swift 项目中使用 GMSAutocompleteFetcher 来搜索地点。在这里,我安装 'GooglePlaces''GooglePlacePicker' 'GoogleMaps' 和 pods 并按照 link 中的方式编写所有内容 https://developers.google.com/places/ios-api/autocomplete#use_the_fetcher 但是在写入 textFieldDidChange 之后,我在委托方法中根据它得到了结果:

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

        }

但在 resultsStr 中获得了价值:

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

应该是"California"

Swift 3.0 代码..

你的 prediction.attributedFullText 属性文本首先在 string 中转换,然后你得到字符串类型的结果。

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