FirebaseDatabase Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
FIRDataSnapshot
@interface FIRDataSnapshot : NSObject
A DataSnapshot contains data from a Firebase Database location. Any time
you read Firebase data, you receive the data as a DataSnapshot.
DataSnapshots are passed to the blocks you attach with
observe(_:with:)
or observeSingleEvent(of:with:)
. 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 DatabaseReference (e.g. with setValue(_:)
).
-
Gets a DataSnapshot 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 DataSnapshot 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 DataSnapshot for the child location.
-
Return true 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
true if data exists at the specified childPathString, else false.
-
Return true if the DataSnapshot has any children.
Declaration
Objective-C
- (BOOL)hasChildren;
Return Value
true if this snapshot has any children, else false.
-
Return true if the DataSnapshot contains a non-null value.
Declaration
Objective-C
- (BOOL)exists;
Return Value
true if this snapshot contains a non-null value, else false.
-
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:
Dictionary
Array
NSNumber
-bridgeable types, including Bool
String
Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) id value;
Return Value
The data as a native object.
-
Gets the number of children for this DataSnapshot.
Declaration
Objective-C
@property (nonatomic, readonly) NSUInteger childrenCount;
Return Value
An integer indicating the number of children.
-
Gets a DatabaseReference for the location that this data came from.
Return Value
A DatabaseReference instance for the location of this data.
-
The key of the location that generated this DataSnapshot.
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSString *_Nonnull key;
Return Value
A String
containing the key for the location of this
DataSnapshot.
-
An iterator for snapshots of the child nodes in this snapshot.
for var child in snapshot.children {
// ...
}
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSEnumerator<FIRDataSnapshot *> *_Nonnull children;
Return Value
An NSEnumerator of the children.
-
The priority of the data in this DataSnapshot.
Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) id priority;
Return Value
The priority as a String
, or nil
if no priority was set.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-03-11 UTC.
[null,null,["Last updated 2025-03-11 UTC."],[],[],null,["FIRDataSnapshot \n\n\n @interface FIRDataSnapshot : NSObject\n\nA DataSnapshot contains data from a Firebase Database location. Any time\nyou read Firebase data, you receive the data as a DataSnapshot.\n\nDataSnapshots are passed to the blocks you attach with\n`observe(_:with:)` or `observeSingleEvent(of:with:)`. They are\nefficiently-generated immutable copies of the data at a Firebase Database\nlocation. They can't be modified and will never change. To modify data at a\nlocation, use a DatabaseReference (e.g. with `setValue(_:)`).\n[Navigating and inspecting a snapshot](#/Navigating-and-inspecting-a-snapshot)\n\n- `\n ``\n ``\n `\n\n [-childSnapshotForPath:](#/c:objc(cs)FIRDataSnapshot(im)childSnapshotForPath:)`\n ` \n Gets a DataSnapshot for the location at the specified relative path.\n The relative path can either be a simple child key (e.g. 'fred')\n or a deeper slash-separated path (e.g. 'fred/name/first'). If the child\n location has no data, an empty DataSnapshot is returned. \n\n Declaration \n Objective-C \n\n - (nonnull FIRDataSnapshot *)childSnapshotForPath:\n (nonnull NSString *)childPathString;\n\n Parameters\n\n Return Value\n\n The DataSnapshot for the child location.\n- `\n ``\n ``\n `\n\n [-hasChild:](#/c:objc(cs)FIRDataSnapshot(im)hasChild:)`\n ` \n Return true if the specified child exists. \n\n Declaration \n Objective-C \n\n - (BOOL)hasChild:(nonnull NSString *)childPathString;\n\n Parameters\n\n Return Value\n\n true if data exists at the specified childPathString, else false.\n- `\n ``\n ``\n `\n\n [-hasChildren](#/c:objc(cs)FIRDataSnapshot(im)hasChildren)`\n ` \n Return true if the DataSnapshot has any children. \n\n Declaration \n Objective-C \n\n - (BOOL)hasChildren;\n\n Return Value\n\n true if this snapshot has any children, else false.\n- `\n ``\n ``\n `\n\n [-exists](#/c:objc(cs)FIRDataSnapshot(im)exists)`\n ` \n Return true if the DataSnapshot contains a non-null value. \n\n Declaration \n Objective-C \n\n - (BOOL)exists;\n\n Return Value\n\ntrue if this snapshot contains a non-null value, else false. \n[Data export](#/Data-export)\n\n- `\n ``\n ``\n `\n\n [-valueInExportFormat](#/c:objc(cs)FIRDataSnapshot(im)valueInExportFormat)`\n ` \n Returns the raw value at this location, coupled with any metadata, such as\n priority.\n\n Priorities, where they exist, are accessible under the \".priority\" key in\n instances of NSDictionary. For leaf locations with priorities, the value will\n be under the \".value\" key. \n\n Declaration \n Objective-C \n\n - (id _Nullable)valueInExportFormat;\n\n[Properties](#/Properties)\n\n- `\n ``\n ``\n `\n\n [value](#/c:objc(cs)FIRDataSnapshot(py)value)`\n ` \n Returns the contents of this data snapshot as native types.\n\n Data types returned:\n - `Dictionary`\n - `Array`\n - `NSNumber`-bridgeable types, including `Bool`\n - `String`\n\n Declaration \n Objective-C \n\n @property (nonatomic, strong, readonly, nullable) id value;\n\n Return Value\n\n The data as a native object.\n- `\n ``\n ``\n `\n\n [childrenCount](#/c:objc(cs)FIRDataSnapshot(py)childrenCount)`\n ` \n Gets the number of children for this DataSnapshot. \n\n Declaration \n Objective-C \n\n @property (nonatomic, readonly) NSUInteger childrenCount;\n\n Return Value\n\n An integer indicating the number of children.\n- `\n ``\n ``\n `\n\n [ref](#/c:objc(cs)FIRDataSnapshot(py)ref)`\n ` \n Gets a DatabaseReference for the location that this data came from. \n\n Declaration \n Objective-C \n\n @property (nonatomic, strong, readonly) ../Classes/FIRDatabaseReference.html *_Nonnull ref;\n\n Return Value\n\n A DatabaseReference instance for the location of this data.\n- `\n ``\n ``\n `\n\n [key](#/c:objc(cs)FIRDataSnapshot(py)key)`\n ` \n The key of the location that generated this DataSnapshot. \n\n Declaration \n Objective-C \n\n @property (nonatomic, strong, readonly) NSString *_Nonnull key;\n\n Return Value\n\n A `String` containing the key for the location of this\n DataSnapshot.\n- `\n ``\n ``\n `\n\n [children](#/c:objc(cs)FIRDataSnapshot(py)children)`\n ` \n An iterator for snapshots of the child nodes in this snapshot. \n\n for var child in snapshot.children {\n // ...\n }\n\n Declaration \n Objective-C \n\n @property (nonatomic, strong, readonly) NSEnumerator\u003cFIRDataSnapshot *\u003e *_Nonnull children;\n\n Return Value\n\n An NSEnumerator of the children.\n- `\n ``\n ``\n `\n\n [priority](#/c:objc(cs)FIRDataSnapshot(py)priority)`\n ` \n The priority of the data in this DataSnapshot. \n\n Declaration \n Objective-C \n\n @property (nonatomic, strong, readonly, nullable) id priority;\n\n Return Value\n\n The priority as a `String`, or `nil` if no priority was set."]]