FIRDataSnapshot


@interface FIRDataSnapshot : NSObject

A FIRDataSnapshot contains data from a Firebase Database location. Any time you read Firebase data, you receive the data as a FIRDataSnapshot.

FIRDataSnapshots are passed to the blocks you attach with observeEventType:withBlock: or observeSingleEvent:withBlock:. They are efficiently-generated immutable copies of the data at a Firebase Database location. They can’t be modified and will never change. To modify data at a location, use a FIRDatabaseReference (e.g. with setValue:).

  • Gets a FIRDataSnapshot 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’). If the child location has no data, an empty FIRDataSnapshot is returned.

    Declaration

    Objective-C

    - (nonnull FIRDataSnapshot *)childSnapshotForPath:
        (nonnull NSString *)childPathString;

    Parameters

    childPathString

    A relative path to the location of child data.

    Return Value

    The FIRDataSnapshot for the child location.

  • Return YES if the specified child exists.

    Declaration

    Objective-C

    - (BOOL)hasChild:(nonnull NSString *)childPathString;

    Parameters

    childPathString

    A relative path to the location of a potential child.

    Return Value

    YES if data exists at the specified childPathString, else NO.

  • Return YES if the DataSnapshot has any children.

    Declaration

    Objective-C

    - (BOOL)hasChildren;

    Return Value

    YES if this snapshot has any children, else NO.

  • Return YES if the DataSnapshot contains a non-null value.

    Declaration

    Objective-C

    - (BOOL)exists;

    Return Value

    YES if this snapshot contains a non-null value, else NO.

  • Returns the raw value at this location, coupled with any metadata, such as priority.

    Priorities, where they exist, are accessible under the .priority key in instances of NSDictionary. For leaf locations with priorities, the value will be under the .value key.

    Declaration

    Objective-C

    - (id _Nullable)valueInExportFormat;
  • Returns the contents of this data snapshot as native types.

    Data types returned:

    • NSDictionary
    • NSArray
    • NSNumber (also includes booleans)
    • NSString

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, nullable) id value;

    Return Value

    The data as a native object.

  • Gets the number of children for this DataSnapshot.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSUInteger childrenCount;

    Return Value

    An integer indicating the number of children.