如何使用Swift从firebase检索数据?

时间:2017-04-09 18:31:57

标签: ios swift firebase firebase-realtime-database

我有这个代码用于从firebase数据库获取数据:

 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)
})

快照的结果有问题,print(recent)有时会打印出那个孩子的所有值(10个值),这是我想要的东西,但有时候它只会打印那个孩子的两个值。不知道为什么。

如何解决这个问题?

这是我的数据库结构:

enter image description here

1 个答案:

答案 0 :(得分:2)

由于我无法发表评论,我只是想问一些问题,我稍后会删除此答案,但您的数据是否同步?你有没有把方法称为你的参考.keepSynced(true)?

相关问题