【问题标题】:How to query Firestore for value in array如何在 Firestore 中查询数组中的值
【发布时间】:2018-09-07 05:43:49
【问题描述】:

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

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

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

Argument labels '(_:, arrayContains:)' do not match any available overloads

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

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

【问题讨论】:

    标签: swift firebase google-cloud-firestore


    【解决方案1】:

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

    【讨论】:

    • 好的,我昨天根据文档将pod 'Firebase/Firestore' 添加到了我的 podfile 中。那不应该给我最新的版本吗?
    • 你的 podfile 是怎么说的?
    • 我查看了终端,它说:Firebase 4.11.0 FirebaseCore 4.0.18 FirebaseFirestore 0.10.4 我运行了 pod update 并且没有执行任何操作,我需要在我的 Firebase/Core pod 之后添加一个版本吗?
    • 哇。你那里有一些很老的 podfile。您可能需要更新 cocoapods 本身。如果这不起作用,请在运行 pod 更新之前尝试显式运行 pod repo update。如果 that 不起作用,请分享您的 podfile 的全部内容。
    • 感谢您的建议,不幸的是它没有奏效。我在上面粘贴了整个 podfile。
    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 2020-07-17
    • 2019-07-03
    相关资源
    最近更新 更多