问题描述
我有这个代码从firebase数据库获取数据:
$ b $ $ $ $ $ $ $ $ $ $ FIRDatabase.database()。reference()。child ():$ {
$ b $如果snapshot.exists(){{}}。child(User1)。child(chat1)
.observeSingleEvent
let recent = snapshot.value as!NSDictionary
$ b $ print(recent)
})
$ b
快照结果有问题, print(recent)
有时会打印该子项的所有值10个值),这是我想要的东西,但有一段时间它只打印该孩子的两个值,我不知道为什么。
如何解决这个问题? p>
这是我的数据库结构:
由于我无法评论,我只想问一下,我稍后会删除这个答案,但是你的数据是同步的吗?你有没有打电话给你的方法yourreference.keepSynced(true)?
I have this code for getting data from firebase database :
FIRDatabase.database().reference().child("Root").child("User1").child("chat1")
.observeSingleEvent(of: .value , with: { snapshot in
if snapshot.exists() {
let recent = snapshot.value as! NSDictionary
print(recent)
})
There is a problem with the result of snapshot, the print(recent)
sometimes prints all values of that child (10 values) which is the thing I want, but some time it prints only two values of that child I don't know why.
How to fix this ?
This is my database structure :
Since I can not comment and I just want to ask something, I will remove this answer later on, but is your data in sync? Did you call the method yourreference.keepSynced(true)?
这篇关于如何使用Swift从Firebase中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!