Zizoo
Zizoo

Reputation: 1754

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 :

enter image description here

Upvotes: 0

Views: 1684

Answers (1)

J. Doe
J. Doe

Reputation: 13013

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

Upvotes: 2

Related Questions