user2722667
user2722667

Reputation: 8651

FIRDatabaseHandle value or childChanged

I am looking for a way to read data form a child and also have it live updated.

I have seen some code examples where people first fetch data using:

ref?.child("posts").child("somechild").observe(.value

Then have another function watching for changes:

ref?.child("posts").child("somechild").observe(.childChanged

But what is the difference between .value and .childChanged in FIRDatabaseHandle ?

Right now I am only using .value and I will both first fetch data then also watch for changes using it, so I dont need .childChanged and this makes me wonder what .childChanged is used for.

Thanks.

Upvotes: 2

Views: 773

Answers (1)

mrabins
mrabins

Reputation: 197

Listen for value events

To read data at a path and listen for changes, use the observeEventType:withBlock orobserveSingleEventOfType:withBlock methods of FIRDatabaseReference to observe FIRDataEventTypeValue events.

Event type Typical usage FIRDataEventTypeValue Read and listen for changes to the entire contents of a path. You can use the FIRDataEventTypeValue event to read the data at a given path, as it exists at the time of the event. This method is triggered once when the listener is attached and again every time the data, including any children, changes. The event callback is passed a snapshot containing all data at that location, including child data. If there is no data, the value of the snapshot returned is nil.

Upvotes: 1

Related Questions