FIRDatabaseQuery


@interface FIRDatabaseQuery : NSObject

A FIRDatabaseQuery instance represents a query over the data at a particular location.

You create one by calling one of the query methods (queryOrderedByChild:, queryStartingAtValue:, etc.) on a FIRDatabaseReference. The query methods can be chained to further specify the data you are interested in observing

  • observeEventType:withBlock: 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

    Swift

    func observe(_ eventType: DataEventType, with block: @escaping (DataSnapshot) -> Void) -> UInt

    Objective-C

    - (FIRDatabaseHandle)
    observeEventType:(FIRDataEventType)eventType
           withBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull))block;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called with initial data and updates. It is passed the data as a FIRDataSnapshot.

    Return Value

    A handle used to unregister this block later using removeObserverWithHandle:

  • observeEventType:andPreviousSiblingKeyWithBlock: 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.

    Use removeObserverWithHandle: to stop receiving updates.

    Declaration

    Swift

    func observe(_ eventType: DataEventType, andPreviousSiblingKeyWith block: @escaping (DataSnapshot, String?) -> Void) -> UInt

    Objective-C

    - (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType
           andPreviousSiblingKeyWithBlock:
               (nonnull void (^)(FIRDataSnapshot *_Nonnull,
                                 NSString *_Nullable))block;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called with initial data and updates. It is passed the data as a FIRDataSnapshot and the previous child’s key.

    Return Value

    A handle used to unregister this block later using removeObserverWithHandle:

  • observeEventType:withBlock: 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 cancelBlock will be called if you will no longer receive new events due to no longer having permission.

    Use removeObserverWithHandle: to stop receiving updates.

    Declaration

    Swift

    func observe(_ eventType: DataEventType, with block: @escaping (DataSnapshot) -> Void, withCancel cancelBlock: ((Error) -> Void)? = nil) -> UInt

    Objective-C

    - (FIRDatabaseHandle)
    observeEventType:(FIRDataEventType)eventType
           withBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull))block
     withCancelBlock:(nullable void (^)(NSError *_Nonnull))cancelBlock;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called with initial data and updates. It is passed the data as a FIRDataSnapshot.

    cancelBlock

    The 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 removeObserverWithHandle:

  • observeEventType:andPreviousSiblingKeyWithBlock: 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 cancelBlock will be called if you will no longer receive new events due to no longer having permission.

    Use removeObserverWithHandle: to stop receiving updates.

    Declaration

    Swift

    func observe(_ eventType: DataEventType, andPreviousSiblingKeyWith block: @escaping (DataSnapshot, String?) -> Void, withCancel cancelBlock: ((Error) -> Void)? = nil) -> UInt

    Objective-C

    - (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType
           andPreviousSiblingKeyWithBlock:
               (nonnull void (^)(FIRDataSnapshot *_Nonnull,
                                 NSString *_Nullable))block
                          withCancelBlock:
                              (nullable void (^)(NSError *_Nonnull))cancelBlock;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called with initial data and updates. It is passed the data as a FIRDataSnapshot and the previous child’s key.

    cancelBlock

    The 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 removeObserverWithHandle:

  • This is equivalent to observeEventType:withBlock:, except the block is immediately canceled after the initial data is returned.

    Declaration

    Swift

    func observeSingleEvent(of eventType: DataEventType, with block: @escaping (DataSnapshot) -> Void)

    Objective-C

    - (void)observeSingleEventOfType:(FIRDataEventType)eventType
                           withBlock:
                               (nonnull void (^)(FIRDataSnapshot *_Nonnull))block;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called. It is passed the data as a FIRDataSnapshot.

  • This is equivalent to observeEventType:withBlock:, except the block is immediately canceled after the initial data is returned. In addition, for FIRDataEventTypeChildAdded, FIRDataEventTypeChildMoved, and FIRDataEventTypeChildChanged events, your block will be passed the key of the previous node by priority order.

    Declaration

    Swift

    func observeSingleEvent(of eventType: DataEventType, andPreviousSiblingKeyWith block: @escaping (DataSnapshot, String?) -> Void)

    Objective-C

    - (void)observeSingleEventOfType:(FIRDataEventType)eventType
        andPreviousSiblingKeyWithBlock:
            (nonnull void (^)(FIRDataSnapshot *_Nonnull, NSString *_Nullable))block;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called. It is passed the data as a FIRDataSnapshot and the previous child’s key.

  • This is equivalent to observeEventType:withBlock:, except the block is immediately canceled after the initial data is returned.

    The cancelBlock will be called if you do not have permission to read data at this location.

    Declaration

    Swift

    func observeSingleEvent(of eventType: DataEventType, with block: @escaping (DataSnapshot) -> Void, withCancel cancelBlock: ((Error) -> Void)? = nil)

    Objective-C

    - (void)
    observeSingleEventOfType:(FIRDataEventType)eventType
                   withBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull))block
             withCancelBlock:(nullable void (^)(NSError *_Nonnull))cancelBlock;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called. It is passed the data as a FIRDataSnapshot.

    cancelBlock

    The block that will be called if you don’t have permission to access this data

  • This is equivalent to observeEventType:withBlock:, except the block is immediately canceled after the initial data is returned. In addition, for FIRDataEventTypeChildAdded, FIRDataEventTypeChildMoved, and FIRDataEventTypeChildChanged events, your block will be passed the key of the previous node by priority order.

    The cancelBlock will be called if you do not have permission to read data at this location.

    Declaration

    Swift

    func observeSingleEvent(of eventType: DataEventType, andPreviousSiblingKeyWith block: @escaping (DataSnapshot, String?) -> Void, withCancel cancelBlock: ((Error) -> Void)? = nil)

    Objective-C

    - (void)observeSingleEventOfType:(FIRDataEventType)eventType
        andPreviousSiblingKeyWithBlock:(nonnull void (^)(FIRDataSnapshot *_Nonnull,
                                                         NSString *_Nullable))block
                       withCancelBlock:
                           (nullable void (^)(NSError *_Nonnull))cancelBlock;

    Parameters

    eventType

    The type of event to listen for.

    block

    The block that should be called. It is passed the data as a FIRDataSnapshot and the previous child’s key.

    cancelBlock

    The block that will be called if you don’t have permission to access this data

  • Detach a block previously attached with observeEventType:withBlock:.

    Declaration

    Swift

    func removeObserver(withHandle handle: UInt)

    Objective-C

    - (void)removeObserverWithHandle:(FIRDatabaseHandle)handle;

    Parameters