BigBurger
BigBurger

Reputation: 81

Firebase observeSigleEvent or observe

Hi all I am trying to retrieve data from firebase

Here is a picture of it enter image description here

In this case:

    self.ref.child("Events").child("2").observeSingleEvent(of: .value, with: {snap in
            //let snap = child as! DataSnapshot
            let event = snap.value as? [[String:Any]]
            print(snap.value)
            let end_time_test = event?["end_time"] as? String

event is nil, it's supposed to put an array in it, it works here

self.ref.child("Events").child("2").observe(.value, with: { (snapshot) in
                for child in snapshot.children{

            let snap = child as! DataSnapshot
            let event = snap.value as? [String:Any]
                print(event )

I'm new to firebase requests thanks in advance.

Upvotes: 0

Views: 1288

Answers (1)

Retterdesdialogs
Retterdesdialogs

Reputation: 3210

Observe is used to get the initial value and after it you get notified if there is something changing.

Observe single event is used to fetch the data only once.

Upvotes: 1

Related Questions