ios - GMSAutocompletePrediction prediction.attributedFullText 不在 swift 3.0 中给出 nsmutablestring

标签 ios swift3 google-places-api gmsautocomplete

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

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

        }

但在 resultsStr 中获得了值(value):

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

应该是“加州”

最佳答案

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
    }

关于ios - GMSAutocompletePrediction prediction.attributedFullText 不在 swift 3.0 中给出 nsmutablestring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45476693/

相关文章:

swift - 如何异步使用 Firebase?数据库读取给出奇怪的结果

iphone - 没有配件按钮的标注配件

ios - 无法访问核心数据文件

ios - UIPanGestureRecognizer 冲突

ios - 同时关闭两个 NavigationController

iOS 11,当用户强行杀死时应用程序不更新位置

android - Google place api,想要获得最近的位置

google-maps - 从 Google Places 检索 Google FID

ios - 如何在 UITableViewCell 中创建 "underline"文本?

ios - GMSAutocompleteViewController 中无法显示取消按钮