FIRDatabase


@interface FIRDatabase : NSObject

The entry point for accessing a Firebase Database. You can get an instance by calling [FIRDatabase database]. To access a location in the database and read or write data, use [FIRDatabase reference].

  • Gets the instance of FIRDatabase for the default FIRApp.

    Declaration

    Swift

    class func database() -> Database

    Objective-C

    + (nonnull FIRDatabase *)database;

    Return Value

    A FIRDatabase instance.

  • Gets an instance of FIRDatabase for a specific FIRApp.

    Declaration

    Swift

    class func database(app: FIRApp) -> Database

    Objective-C

    + (nonnull FIRDatabase *)databaseForApp:(nonnull FIRApp *)app;

    Parameters

    app

    The FIRApp to get a FIRDatabase for.

    Return Value

    A FIRDatabase instance.

  • app

    The FIRApp instance to which this FIRDatabase belongs.

    Declaration

    Swift

    weak var app: FIRApp? { get }

    Objective-C

    @property (readonly, nonatomic) FIRApp *_Nullable app;
  • Gets a FIRDatabaseReference for the root of your Firebase Database.

    Declaration

    Swift

    func reference() -> DatabaseReference

    Objective-C

    - (nonnull FIRDatabaseReference *)reference;
  • Gets a FIRDatabaseReference for the provided path.

    Declaration

    Swift

    func reference(withPath path: String) -> DatabaseReference

    Objective-C

    - (nonnull FIRDatabaseReference *)referenceWithPath:(nonnull NSString *)path;

    Parameters

    path

    Path to a location in your Firebase Database.

    Return Value

    A FIRDatabaseReference pointing to the specified path.

  • Gets a FIRDatabaseReference for the provided URL. The URL must be a URL to a path within this Firebase Database. To create a FIRDatabaseReference to a different database, create a FIRApp} with a FIROptions object configured with the appropriate database URL.

    Declaration

    Swift

    func reference(fromURL databaseUrl: String) -> DatabaseReference

    Objective-C

    - (nonnull FIRDatabaseReference *)referenceFromURL:
        (nonnull NSString *)databaseUrl;

    Parameters

    databaseUrl

    A URL to a path within your database.

    Return Value

    A FIRDatabaseReference for the provided URL.

  • The Firebase Database client automatically queues writes and sends them to the server at the earliest opportunity, depending on network connectivity. In some cases (e.g. offline usage) there may be a large number of writes waiting to be sent. Calling this method will purge all outstanding writes so they are abandoned.

    All writes will be purged, including transactions and onDisconnect writes. The writes will be rolled back locally, perhaps triggering events for affected event listeners, and the client will not (re-)send them to the Firebase Database backend.

    Declaration

    Swift

    func purgeOutstandingWrites()

    Objective-C

    - (void)purgeOutstandingWrites;
  • Shuts down our connection to the Firebase Database backend until goOnline is called.

    Declaration

    Swift

    func goOffline()

    Objective-C

    - (void)goOffline;
  • Resumes our connection to the Firebase Database backend after a previous goOffline call.

    Declaration

    Swift

    func goOnline()

    Objective-C

    - (void)goOnline;
  • The Firebase Database client will cache synchronized data and keep track of all writes you’ve initiated while your application is running. It seamlessly handles intermittent network connections and re-sends write operations when the network connection is restored.

    However by default your write operations and cached data are only stored in-memory and will be lost when your app restarts. By setting this value to YES, the data will be persisted to on-device (disk) storage and will thus be available again when the app is restarted (even when there is no network connectivity at that time). Note that this property must be set before creating your first Database reference and only needs to be called once per application.

    Declaration

    Swift

    var isPersistenceEnabled: Bool { get set }

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL persistenceEnabled;
  • By default the Firebase Database client will use up to 10MB of disk space to cache data. If the cache grows beyond this size, the client will start removing data that hasn’t been recently used. If you find that your application caches too little or too much data, call this method to change the cache size. This property must be set before creating your first FIRDatabaseReference and only needs to be called once per application.

    Note that the specified cache size is only an approximation and the size on disk may temporarily exceed it at times. Cache sizes smaller than 1 MB or greater than 100 MB are not supported.

    Declaration

    Swift

    var persistenceCacheSizeBytes: UInt { get set }

    Objective-C

    @property (assign, readwrite, nonatomic) NSUInteger persistenceCacheSizeBytes;
  • Sets the dispatch queue on which all events are raised. The default queue is the main queue.

    Note that this must be set before creating your first Database reference.

    Declaration

    Swift

    var callbackQueue: DispatchQueue { get set }

    Objective-C

    @property (readwrite, strong, nonatomic) dispatch_queue_t _Nonnull callbackQueue;
  • Enables verbose diagnostic logging.

    Declaration

    Swift

    class func setLoggingEnabled(_ enabled: Bool)

    Objective-C

    + (void)setLoggingEnabled:(BOOL)enabled;

    Parameters

    enabled

    YES to enable logging, NO to disable.

  • Retrieve the Firebase Database SDK version.

    Declaration

    Swift

    class func sdkVersion() -> String

    Objective-C

    + (nonnull NSString *)sdkVersion;