You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GMSAutocompleteFilter type属性弃用后使用types报错求助

解决GMSAutocompleteFilter types属性报错问题

问题重现

原代码触发弃用警告:

let filter = GMSAutocompleteFilter()
filter.type = .address // 'type' is deprecated: type property is deprecated in favor of types

改为官方推荐的数组写法后出现错误:

let filter = GMSAutocompleteFilter()
filter.types = [.address] // Type 'Array.ArrayLiteralElement' (aka 'String') has no member 'address'

问题原因

最新版本的Google Places SDK中,GMSAutocompleteFilter的types属性类型已从枚举改为字符串数组,不再直接支持GMSPlacesAutocompleteTypeFilter枚举值的简写调用。

解决方案

有两种可行的修复方式:

  1. 使用枚举的rawValue转换
    直接将原枚举成员转为对应字符串:
import GooglePlaces

let filter = GMSAutocompleteFilter()
filter.types = [GMSPlacesAutocompleteTypeFilter.address.rawValue]
  1. 使用SDK提供的字符串常量
    Google Places SDK定义了一系列预定义的类型字符串常量,可直接使用:
import GooglePlaces

let filter = GMSAutocompleteFilter()
filter.types = [kGMSPlaceTypeAddress]

额外检查

  • 确保已正确导入GooglePlaces框架
  • 确认SDK版本为最新(可通过CocoaPods执行pod update GooglePlaces更新)

内容的提问来源于stack exchange,提问作者Nicola Salvaro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 09:45:49