gpt4 book ai didi

ios - Firebase 查询字符串数组

转载 作者:行者123 更新时间:2023-11-30 13:07:21 25 4
gpt4 key购买 nike

我想知道是否有人对如何在“Firebase”中一次从数组中查询多个字符串有任何想法。基本上像使用 AND 条件一样进行查询。我已经研究过以一百种不同的方式重组我的数据,但没有一种对我有用。另外,我的数据太多,无法转储所有数据,然后在执行查询后与我的数组匹配。非常感谢任何帮助或建议。

var uniqueStoreId = [“1”, “2”, “3”, “4”, “5”, “6”]
var posts = [Post]()

ref.queryOrderedByChild("storeId").queryEqualToValue("\(uniqueStoreId)").observeEventType(.Value, withBlock: {snapshot in
if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshot{
if let postDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let post = Post(postKey: key, postData: postDict)
self.posts.insert(post, atIndex: 0)
}
}
}

})

最佳答案

//做这样的事情,检查它是数组还是字典,然后添加一个数组,然后根据需要使用..享受

                    var arrMessage = [MessageFirebase]()

if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {

//If its a Array then use below method
for snap in snapshots {
if let postDictionary = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let message = MessageFirebase(key: key, dictionary: postDictionary)
// Items are returned chronologically, but it's more fun with the newest jokes first.

//if needed
arrMessage.insert(message, atIndex: 0)
}
}

//If its a dictionary then use below method
if !(arrMessage.count > 0) {
let key = snapshot.key
let message = MessageFirebase(key: key, dictionary: snapshot.value!)
// Items are returned chronologically, but it's more fun with the newest jokes first.

//if needed
arrMessage.insert(message, atIndex: 0)
}
}

关于ios - Firebase 查询字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39181124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com