FIRDatabaseReference


@interface FIRDatabaseReference : FIRDatabaseQuery

A FIRDatabaseReference represents a particular location in your Firebase Database and can be used for reading or writing data to that Firebase Database location.

This class is the starting point for all Firebase Database operations. After you’ve obtained your first FIRDatabaseReference via [FIRDatabase reference], you can use it to read data (ie. observeEventType:withBlock:), write data (ie. setValue:), and to create new FIRDatabaseReferences (ie. child:).

  • Gets a FIRDatabaseReference for the location at the specified relative path. The relative path can either be a simple child key (e.g. ‘fred’) or a deeper slash-separated path (e.g. ‘fred/name/first’).

    Declaration

    Objective-C

    - (nonnull FIRDatabaseReference *)child:(nonnull NSString *)pathString;

    Parameters

    pathString

    A relative path from this location to the desired child location.

    Return Value

    A FIRDatabaseReference for the specified relative path.

  • childByAutoId generates a new child location using a unique key and returns a FIRDatabaseReference to it. This is useful when the children of a Firebase Database location represent a list of items.

    The unique key generated by childByAutoId: is prefixed with a client-generated timestamp so that the resulting list will be chronologically-sorted.

    Declaration

    Objective-C

    - (nonnull FIRDatabaseReference *)childByAutoId;

    Return Value

    A FIRDatabaseReference for the generated location.

  • Write data to this Firebase Database location.

    This will overwrite any data at this location and all child locations.

    Data types that can be set are:

    • NSString – @Hello World
    • NSNumber (also includes boolean) – @YES, @43, @4.333
    • NSDictionary – @{@key: @value, @nested: @{@another: @value} }
    • NSArray

    The effect of the write will be visible immediately and the corresponding events will be triggered. Synchronization of the data to the Firebase Database servers will also be started.

    Passing null for the new value is equivalent to calling remove:; all data at this location or any child location will be deleted.

    Note that setValue: will remove any priority stored at this location, so if priority is meant to be preserved, you should use setValue:andPriority: instead.

    Declaration

    Objective-C

    - (void)setValue:(nullable id)value;

    Parameters

    value

    The value to be written.

  • The same as setValue: with a block that gets triggered after the write operation has been committed to the Firebase Database servers.

    Declaration

    Objective-C

    - (void)setValue:(nullable id)value
        withCompletionBlock:(nonnull void (^)(NSError *_Nullable,
                                              FIRDatabaseReference *_Nonnull))block;

    Parameters

    value

    The value to be written.

    block

    The block to be called after the write has been committed to the Firebase Database servers.

  • The same as setValue: with an additional priority to be attached to the data being written. Priorities are used to order items.

    Declaration

    Objective-C

    - (void)setValue:(nullable id)value andPriority:(nullable id)priority;

    Parameters

    value

    The value to be written.

    priority

    The priority to be attached to that data.

  • The same as setValue:andPriority: with a block that gets triggered after the write operation has been committed to the Firebase Database servers.

    Declaration

    Objective-C

    - (void)setValue:(nullable id)value
                andPriority:(nullable id)priority
        withCompletionBlock:(nonnull void (^)(NSError *_Nullable,
                                              FIRDatabaseReference *_Nonnull))block;

    Parameters

    value

    The value to be written.

    priority

    The priority to be attached to that data.

    block

    The block to be called after the write has been committed to the Firebase Database servers.

  • Remove the data at this Firebase Database location. Any data at child locations will also be deleted.

    The effect of the delete will be visible immediately and the corresponding events will be triggered. Synchronization of the delete to the Firebase Database servers will also be started.

    remove: is equivalent to calling setValue:nil

    Declaration

    Objective-C

    - (void)removeValue;
  • The same as remove: with a block that gets triggered after the remove operation has been committed to the Firebase Database servers.

    Declaration

    Objective-C

    - (void)removeValueWithCompletionBlock:
        (nonnull void (^)(NSError *_Nullable, FIRDatabaseReference *_Nonnull))block;

    Parameters