swift - 如何在 Firestore 中查询数组中的值

标签 swift firebase google-cloud-firestore

根据 Firebase Firestore 文档,为了查询数组包含特定值的集合,您可以这样做:

citiesRef.whereField("regions", arrayContains: "west_coast")

只有当我尝试在 Swift 4 中编写时,才会出现以下错误:

参数标签“(_:, arrayContains:)”不匹配任何可用的重载

查看可用的重载会产生以下结果:

Query whereField(field: String, isEqualTo: Any)
Query whereField(path: FieldPath, isEqualTo: Any)
Query whereField(field: String, isLessThan: Any)
Query whereField(path: FieldPath, isLessThan: Any)
Query whereField(field: String, isGreaterThan: Any)
Query whereField(path: FieldPath, isGreaterThan: Any)
Query whereField(field: String, isLessThanOrEqualTo: Any)
Query whereField(path: FieldPath, isLessThanOrEqualTo: Any)
Query whereField(field: String, isGreaterThanOrEqualTo: Any)
Query whereField(path: FieldPath, isGreaterThanOrEqualTo: Any)

其中没有关于数组或包含的内容。文档过时了吗?我错过了什么? Docs found here

我的播客文件:

 platform :ios, '9.0'

target 'Appname' do
use_frameworks!

# Pods for Appname

pod ‘Firebase/Core’
pod ‘Firebase/Auth’
pod 'Firebase/Database'
pod 'Firebase/Firestore'
pod 'Firebase/Storage'
pod 'Firebase/Invites'
pod 'SwiftGifOrigin', '~> 1.6'
pod 'Kingfisher', '~> 4.0'
pod 'AudioKit', '~> 4.0'
pod 'KSTokenView', '~> 4.0'
pod 'ReachabilitySwift'
pod 'ZFTokenField'
pod 'SlackTextViewController'
pod 'RealmSwift'

target 'AppnameTests' do
 inherit! :search_paths
 # Pods for testing
end

target 'AppnameUITests' do
 inherit! :search_paths
 # Pods for testing
end

end

最佳答案

arrayContains 支持已在 Firestore pod 的 5.5.0 中发布。确保您使用的是该版本或更高版本。 Read the release notes here.

关于swift - 如何在 Firestore 中查询数组中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52215966/

相关文章:

swift - 如何同时委托(delegate)ARSession和AVCaptureSession?

firebase - 如何使用 api key 向 Firebase 实时数据库发出经过身份验证的请求

ios - 访问 NSDictionary 中的信息

xcode - ld : -bundle and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together

node.js - 如何使用 firestore admin nodejs sdk 设置服务器时间戳?

angular - 尝试使用 request.path 设置 Cloud Firestore 安全规则

javascript - Firebase firestore 云函数显示错误 : Invalid use of type "undefined" as a Firestore argument

firebase - 移动云消防站集合

ios - 如何使用 swift 在 ViewController 上隐藏 uicollectionview

javascript - Firebase 中有序列表的性能