简体   繁体   中英

How to retrieve data from firebase using Swift?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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