简体   繁体   English

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

[英]How to retrieve data from firebase using Swift?

I have this code for getting data from firebase 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)
})

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. 快照的结果有问题, print(recent)有时会打印该子项的所有值(10个值),这是我想要的,但是有时它只打印该子项的两个值,我不知道为什么。

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)? 您是否将该方法称为yourreference.keepSynced(true)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM