FIRDatabaseQuery
@interface FIRDatabaseQuery : NSObjectA DatabaseQuery instance represents a query over the data at a particular
location.
You create one by calling one of the query methods (queryOrdered(byChild:),
queryStarting(atValue:), etc.) on a DatabaseReference. The query methods
can be chained to further specify the data you are interested in observing.
-
This method is used to listen for data changes at a particular location. This is the primary way to read data from the Firebase Database. Your block will be triggered for the initial data and again whenever the data changes.
Use removeObserverWithHandle: to stop receiving updates.
Declaration
Objective-C
- (FIRDatabaseHandle) observeEventType:(FIRDataEventType)eventType withBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull))block;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called with initial data and updates. It is passed the data as a
DataSnapshot.Return Value
A handle used to unregister this block later using
removeObserver(withHandle:) -
This method is used to listen for data changes at a particular location. This is the primary way to read data from the Firebase Database. Your block will be triggered for the initial data and again whenever the data changes. In addition, for
DataEventTypeChildAdded,DataEventTypeChildMoved, andDataEventTypeChildChangedevents, your block will be passed the key of the previous node by priority order.Use
removeObserver(withHandle:)to stop receiving updates.Declaration
Objective-C
- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType andPreviousSiblingKeyWithBlock: (nonnull void (^)(FIRDataSnapshot *_Nonnull, NSString *_Nullable))block;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called with initial data and updates. It is passed the data as a
DataSnapshotand the previous child’s key.Return Value
A handle used to unregister this block later using
removeObserver(withHandle:) -
This method is used to listen for data changes at a particular location. This is the primary way to read data from the Firebase Database. Your block will be triggered for the initial data and again whenever the data changes.
The
cancelBlockwill be called if you will no longer receive new events due to no longer having permission.Use
removeObserver(withHandle:)to stop receiving updates.Declaration
Objective-C
- (FIRDatabaseHandle) observeEventType:(FIRDataEventType)eventType withBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull))block withCancelBlock:(nullable void (^)(NSError *_Nonnull))cancelBlock;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called with initial data and updates. It is passed the data as a
DataSnapshot.cancelBlockThe block that should be called if this client no longer has permission to receive these events
Return Value
A handle used to unregister this block later using
removeObserver(withHandle:) -
This method is used to listen for data changes at a particular location. This is the primary way to read data from the Firebase Database. Your block will be triggered for the initial data and again whenever the data changes. In addition, for
FIRDataEventTypeChildAdded,FIRDataEventTypeChildMoved, and FIRDataEventTypeChildChanged events, your block will be passed the key of the previous node by priority order.The
cancelBlockwill be called if you will no longer receive new events due to no longer having permission.Use
removeObserver(withHandle:)to stop receiving updates.Declaration
Objective-C
- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType andPreviousSiblingKeyWithBlock: (nonnull void (^)(FIRDataSnapshot *_Nonnull, NSString *_Nullable))block withCancelBlock: (nullable void (^)(NSError *_Nonnull))cancelBlock;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called with initial data and updates. It is passed the data as a
DataSnapshotand the previous child’s key.cancelBlockThe block that should be called if this client no longer has permission to receive these events
Return Value
A handle used to unregister this block later using
removeObserver(withHandle:) -
This method is used to get the most up-to-date value for this query. This method updates the cache and raises events if successful. If not connected, it returns a locally-cached value.
Declaration
Objective-C
- (void)getDataWithCompletionBlock: (void (^_Nonnull)(NSError *_Nullable, FIRDataSnapshot *_Nullable))block;Parameters
blockThe block that should be called with the most up-to-date value of this query, or an error if no such value could be retrieved.
-
This is equivalent to
observe(_:with:), except the block is immediately canceled after the initial data is returned.Declaration
Objective-C
- (void)observeSingleEventOfType:(FIRDataEventType)eventType withBlock: (nonnull void (^)(FIRDataSnapshot *_Nonnull))block;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called. It is passed the data as a
DataSnapshot. -
This is equivalent to
observe(_:with:), except the block is immediately canceled after the initial data is returned. In addition, forDataEventTypeChildAdded,DataEventTypeChildMoved, andDataEventTypeChildChangedevents, your block will be passed the key of the previous node by priority order.Declaration
Objective-C
- (void)observeSingleEventOfType:(FIRDataEventType)eventType andPreviousSiblingKeyWithBlock: (nonnull void (^)(FIRDataSnapshot *_Nonnull, NSString *_Nullable))block;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called. It is passed the data as a
DataSnapshotand the previous child’s key. -
This is equivalent to
observe(_:with:), except the block is immediately canceled after the initial data is returned.The
cancelBlockwill be called if you do not have permission to read data at this location.Declaration
Objective-C
- (void) observeSingleEventOfType:(FIRDataEventType)eventType withBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull))block withCancelBlock:(nullable void (^)(NSError *_Nonnull))cancelBlock;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called. It is passed the data as a
DataSnapshot.cancelBlockThe block that will be called if you don’t have permission to access this data
-
This is equivalent to
observe(_:with:), except the block is immediately canceled after the initial data is returned. In addition, forDataEventTypeChildAdded,DataEventTypeChildMoved, andDataEventTypeChildChangedevents, your block will be passed the key of the previous node by priority order.The
cancelBlockwill be called if you do not have permission to read data at this location.Declaration
Objective-C
- (void)observeSingleEventOfType:(FIRDataEventType)eventType andPreviousSiblingKeyWithBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull, NSString *_Nullable))block withCancelBlock: (nullable void (^)(NSError *_Nonnull))cancelBlock;Parameters
eventTypeThe type of event to listen for.
blockThe block that should be called. It is passed the data as a
DataSnapshotand the previous child’s key.cancelBlockThe block that will be called if you don’t have permission to access this data
-
Detach a block previously attached with
observe(_:with:), or another query observation method. After this method is called, the associated block registered to receive snapshot updates will no longer be invoked.Declaration
Objective-C
- (void)removeObserverWithHandle:(FIRDatabaseHandle)handle;Parameters
handleThe handle returned by the call to
observe(_:with:)which we are trying to remove. -
Detach all blocks previously attached to this Firebase Database location with
observe(_:with:)and other query observation methods.Declaration
Objective-C
- (void)removeAllObservers; -
By calling
keepSynced(true)on a location, the data for that location will automatically be downloaded and kept in sync, even when no listeners are attached for that location. Additionally, while a location is kept synced, it will not be evicted from the persistent disk cache.Declaration
Objective-C
- (void)keepSynced:(BOOL)keepSynced;Parameters
keepSyncedPass true to keep this location synchronized, or false to stop synchronization.
-
This method is used to generate a reference to a limited view of the data at this location. The
DatabaseQueryinstance returned byqueryLimited(toFirst:)will respond to at most the first limit child nodes.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryLimitedToFirst:(NSUInteger)limit;Parameters
limitThe upper bound, inclusive, for the number of child nodes to receive events for
Return Value
A
DatabaseQueryinstance, limited to at most limit child nodes. -
queryLimited(toLast:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned by this method will respond to at most the last limit child nodes.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryLimitedToLast:(NSUInteger)limit;Parameters
limitThe upper bound, inclusive, for the number of child nodes to receive events for
Return Value
A
DatabaseQueryinstance, limited to at most limit child nodes. -
This method is used to generate a reference to a view of the data that’s been sorted by the values of a particular child key. This method is intended to be used in combination with
queryStarting(atValue:),queryEnding(atValue:), orqueryEqual(toValue:).Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryOrderedByChild:(nonnull NSString *)key;Parameters
keyThe child key to use in ordering data visible to the returned
DatabaseQueryReturn Value
A
DatabaseQueryinstance, ordered by the values of the specified child key. -
queryOrdered(byKey:) is used to generate a reference to a view of the data that's been sorted by child key. This method is intended to be used in combination withqueryStarting(atValue:),queryEnding(atValue:), orqueryEqual(toValue:)`.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryOrderedByKey;Return Value
A
DatabaseQueryinstance, ordered by child keys. -
queryOrdered(byValue:)is used to generate a reference to a view of the data that’s been sorted by child value. This method is intended to be used in combination withqueryStarting(atValue:),queryEnding(atValue:), orqueryEqual(toValue:).Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryOrderedByValue;Return Value
A
DatabaseQueryinstance, ordered by child value. -
queryOrdered(byPriority:) is used to generate a reference to a view of the data that's been sorted by child priority. This method is intended to be used in combination withqueryStarting(atValue:),queryEnding(atValue:), orqueryEqual(toValue:)`.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryOrderedByPriority;Return Value
A
DatabaseQueryinstance, ordered by child priorities. -
queryStarting(atValue:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryStarting(atValue:)will respond to events at nodes with a value greater than or equal tostartValue.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryStartingAtValue:(nullable id)startValue;Parameters
startValueThe lower bound, inclusive, for the value of data visible to the returned
DatabaseQueryReturn Value
A
DatabaseQueryinstance, limited to data with value greater than or equal tostartValue -
queryStarting(atValue:childKey:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryStarting(atValue:childKey:)will respond to events at nodes with a value greater thanstartValue, or equal tostartValueand with a key greater than or equal tochildKey. This is most useful when implementing pagination in a case where multiple nodes can match thestartValue.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryStartingAtValue:(nullable id)startValue childKey: (nullable NSString *)childKey;Parameters
startValueThe lower bound, inclusive, for the value of data visible to the returned
DatabaseQuerychildKeyThe lower bound, inclusive, for the key of nodes with value equal to
startValueReturn Value
A
DatabaseQueryinstance, limited to data with value greater than or equal tostartValue -
queryStarting(afterValue:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryStarting(afterValue:)will respond to events at nodes with a value greater than startAfterValue.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryStartingAfterValue: (nullable id)startAfterValue;Parameters
startAfterValueThe lower bound, exclusive, for the value of data visible to the returned
DatabaseQueryReturn Value
A
DatabaseQueryinstance, limited to data with value greaterstartAfterValue -
queryStarting(afterValue:childKey:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryStarting(afterValue:childKey:)will respond to events at nodes with a value greater thanstartAfterValue, or equal tostartAfterValueand with a key greater thanchildKey. This is most useful when implementing pagination in a case where multiple nodes can match thestartAfterValue.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *) queryStartingAfterValue:(nullable id)startAfterValue childKey:(nullable NSString *)childKey;Parameters
startAfterValueThe lower bound, inclusive, for the value of data visible to the returned
DatabaseQuerychildKeyThe lower bound, exclusive, for the key of nodes with value equal to
startAfterValueReturn Value
A
DatabaseQueryinstance, limited to data with value greater thanstartAfterValue, or equal tostartAfterValuewith a key greater thanchildKey -
queryEnding(atValue:)is used to generate a reference to a limited view of the data at this location. The DatabaseQuery instance returned byqueryEnding(atValue:)will respond to events at nodes with a value less than or equal toendValue.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryEndingAtValue:(nullable id)endValue;Parameters
endValueThe upper bound, inclusive, for the value of data visible to the returned
DatabaseQueryReturn Value
A
DatabaseQueryinstance, limited to data with value less than or equal toendValue -
queryEnding(atValue:childKey:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryEnding(atValue:childKey:)will respond to events at nodes with a value less thanendValue, or equal toendValueand with a key less than or equal tochildKey. This is most useful when implementing pagination in a case where multiple nodes can match theendValue.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryEndingAtValue:(nullable id)endValue childKey:(nullable NSString *)childKey;Parameters
endValueThe upper bound, inclusive, for the value of data visible to the returned
DatabaseQuerychildKeyThe upper bound, inclusive, for the key of nodes with value equal to
endValueReturn Value
A
DatabaseQueryinstance, limited to data with value less than or equal toendValue -
queryEnding(beforeValue:) is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryEnding(beforeValue:)will respond to events at nodes with a value less thanendValue`.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryEndingBeforeValue:(nullable id)endValue;Parameters
endValueThe upper bound, exclusive, for the value of data visible to the returned
DatabaseQueryReturn Value
A
DatabaseQueryinstance, limited to data with value less thanendValue -
queryEnding(beforeValue:childKey:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryEnding(beforeValue:childKey:)will respond to events at nodes with a value less thanendValue, or equal toendValueand with a key less than childKey.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryEndingBeforeValue:(nullable id)endValue childKey: (nullable NSString *)childKey;Parameters
endValueThe upper bound, inclusive, for the value of data visible to the returned
DatabaseQuerychildKeyThe upper bound, exclusive, for the key of nodes with value equal to endValue
Return Value
A
DatabaseQueryinstance, limited to data with value less than or equal to endValue -
queryEqual(toValue:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryEqual(toValue:)will respond to events at nodes with a value equal to the supplied argument.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryEqualToValue:(nullable id)value;Parameters
valueThe value that the data returned by this
DatabaseQuerywill haveReturn Value
A
DatabaseQueryinstance, limited to data with the supplied value. -
queryEqual(toValue:childKey:)is used to generate a reference to a limited view of the data at this location. TheDatabaseQueryinstance returned byqueryEqual(toValue:childKey:)will respond to events at nodes with a value equal to the supplied argument and with their key equal tochildKey. There will be at most one node that matches because child keys are unique.Declaration
Objective-C
- (nonnull FIRDatabaseQuery *)queryEqualToValue:(nullable id)value childKey:(nullable NSString *)childKey;Parameters
valueThe value that the data returned by this
DatabaseQuerywill havechildKeyThe name of nodes with the right value
Return Value
A
DatabaseQueryinstance, limited to data with the supplied value and the key.
-
Gets a
DatabaseReferencefor the location of this query.Declaration
Objective-C
@property (nonatomic, strong, readonly) FIRDatabaseReference *_Nonnull ref;Return Value
A
DatabaseReferencefor the location of this query.