How to retrieve data from firebase using Swift?

白昼怎懂夜的黑 提交于 2020-01-17 06:55:21

问题


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 :


回答1:


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



来源:https://stackoverflow.com/questions/43310411/how-to-retrieve-data-from-firebase-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!