Stay organized with collections
Save and categorize content based on your preferences.
FIRDatabase
@interfaceFIRDatabase:NSObject
The entry point for accessing a Firebase Database. You can get an instance
by calling Database.database(). To access a location in the database and
read or write data, use FIRDatabase.reference().
Gets a DatabaseReference for the provided URL. The URL must be a URL to a
path within this Firebase Database. To create a DatabaseReference to a
different database, create a FirebaseApp with an Options object
configured with the appropriate database 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.
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
true, 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 DatabaseReference and only needs to be called once per
application.
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
DatabaseReference 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-11 UTC."],[],[],null,["# FirebaseDatabase Framework Reference\n\nFIRDatabase\n===========\n\n\n @interface FIRDatabase : NSObject\n\nThe entry point for accessing a Firebase Database. You can get an instance\nby calling `Database.database()`. To access a location in the database and\nread or write data, use `FIRDatabase.reference()`.\n- `\n ``\n ``\n `\n\n ### [-init](#/c:objc(cs)FIRDatabase(im)init)\n\n `\n ` \n Unavailable\n\n use the database method instead \n The NSObject initializer that has been marked as unavailable. Use the\n `database` class method instead. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull instancetype)init;\n\n- `\n ``\n ``\n `\n\n ### [+database](#/c:objc(cs)FIRDatabase(cm)database)\n\n `\n ` \n Gets the instance of `Database` for the default `FirebaseApp`. \n\n #### Declaration\n\n Objective-C \n\n + (nonnull FIRDatabase *)database;\n\n #### Return Value\n\n A `Database` instance.\n- `\n ``\n ``\n `\n\n ### [+databaseWithURL:](#/c:objc(cs)FIRDatabase(cm)databaseWithURL:)\n\n `\n ` \n Gets a `Database` instance for the specified URL. \n\n #### Declaration\n\n Objective-C \n\n + (nonnull FIRDatabase *)databaseWithURL:(nonnull NSString *)url;\n\n #### Parameters\n\n |-------------|---------------------------------------------------------------|\n | ` `*url*` ` | The URL to the Firebase Database instance you want to access. |\n\n #### Return Value\n\n A `Database` instance.\n- `\n ``\n ``\n `\n\n ### [+databaseForApp:URL:](#/c:objc(cs)FIRDatabase(cm)databaseForApp:URL:)\n\n `\n ` \n Gets a `Database` instance for the specified URL, using the specified\n `FirebaseApp`. \n\n #### Declaration\n\n Objective-C \n\n + (nonnull FIRDatabase *)databaseForApp:(nonnull FIRApp *)app\n URL:(nonnull NSString *)url;\n\n #### Parameters\n\n |-------------|---------------------------------------------------------------|\n | ` `*app*` ` | The app to get a `Database` for. |\n | ` `*url*` ` | The URL to the Firebase Database instance you want to access. |\n\n #### Return Value\n\n A `Database` instance.\n- `\n ``\n ``\n `\n\n ### [+databaseForApp:](#/c:objc(cs)FIRDatabase(cm)databaseForApp:)\n\n `\n ` \n Gets an instance of `Database` for a specific `FirebaseApp`. \n\n #### Declaration\n\n Objective-C \n\n + (nonnull FIRDatabase *)databaseForApp:(nonnull FIRApp *)app;\n\n #### Parameters\n\n |-------------|----------------------------------|\n | ` `*app*` ` | The app to get a `Database` for. |\n\n #### Return Value\n\n A `Database` instance.\n- `\n ``\n ``\n `\n\n ### [app](#/c:objc(cs)FIRDatabase(py)app)\n\n `\n ` \n The app instance to which this `Database` belongs. \n\n #### Declaration\n\n Objective-C \n\n @property (nonatomic, weak, readonly) FIRApp *_Nullable app;\n\n- `\n ``\n ``\n `\n\n ### [-reference](#/c:objc(cs)FIRDatabase(im)reference)\n\n `\n ` \n Gets a `DatabaseReference` for the root of your Firebase Database. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull ../Classes/FIRDatabaseReference.html *)reference;\n\n- `\n ``\n ``\n `\n\n ### [-referenceWithPath:](#/c:objc(cs)FIRDatabase(im)referenceWithPath:)\n\n `\n ` \n Gets a `DatabaseReference` for the provided path. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull ../Classes/FIRDatabaseReference.html *)referenceWithPath:(nonnull NSString *)path;\n\n #### Parameters\n\n |--------------|-----------------------------------------------|\n | ` `*path*` ` | Path to a location in your Firebase Database. |\n\n #### Return Value\n\n A `DatabaseReference` pointing to the specified path.\n- `\n ``\n ``\n `\n\n ### [-referenceFromURL:](#/c:objc(cs)FIRDatabase(im)referenceFromURL:)\n\n `\n ` \n Gets a `DatabaseReference` for the provided URL. The URL must be a URL to a\n path within this Firebase Database. To create a `DatabaseReference` to a\n different database, create a `FirebaseApp` with an `Options` object\n configured with the appropriate database URL. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull ../Classes/FIRDatabaseReference.html *)referenceFromURL:\n (nonnull NSString *)databaseUrl;\n\n #### Parameters\n\n |---------------------|---------------------------------------|\n | ` `*databaseUrl*` ` | A URL to a path within your database. |\n\n #### Return Value\n\n A `DatabaseReference` for the provided URL.\n- `\n ``\n ``\n `\n\n ### [-purgeOutstandingWrites](#/c:objc(cs)FIRDatabase(im)purgeOutstandingWrites)\n\n `\n ` \n The Firebase Database client automatically queues writes and sends them to\n the server at the earliest opportunity, depending on network connectivity. In\n some cases (e.g. offline usage) there may be a large number of writes waiting\n to be sent. Calling this method will purge all outstanding writes so they are\n abandoned.\n\n All writes will be purged, including transactions and onDisconnect writes.\n The writes will be rolled back locally, perhaps triggering events for\n affected event listeners, and the client will not (re-)send them to the\n Firebase Database backend. \n\n #### Declaration\n\n Objective-C \n\n - (void)purgeOutstandingWrites;\n\n- `\n ``\n ``\n `\n\n ### [-goOffline](#/c:objc(cs)FIRDatabase(im)goOffline)\n\n `\n ` \n Shuts down the connection to the Firebase Database backend until `goOnline()`\n is called. \n\n #### Declaration\n\n Objective-C \n\n - (void)goOffline;\n\n- `\n ``\n ``\n `\n\n ### [-goOnline](#/c:objc(cs)FIRDatabase(im)goOnline)\n\n `\n ` \n Resumes the connection to the Firebase Database backend after a previous\n goOffline() call. \n\n #### Declaration\n\n Objective-C \n\n - (void)goOnline;\n\n- `\n ``\n ``\n `\n\n ### [persistenceEnabled](#/c:objc(cs)FIRDatabase(py)persistenceEnabled)\n\n `\n ` \n The Firebase Database client will cache synchronized data and keep track of\n all writes you've initiated while your application is running. It seamlessly\n handles intermittent network connections and re-sends write operations when\n the network connection is restored.\n\n However by default your write operations and cached data are only stored\n in-memory and will be lost when your app restarts. By setting this value to\n `true`, the data will be persisted to on-device (disk) storage and will thus\n be available again when the app is restarted (even when there is no network\n connectivity at that time). Note that this property must be set before\n creating your first `DatabaseReference` and only needs to be called once per\n application. \n\n #### Declaration\n\n Objective-C \n\n @property (nonatomic) BOOL persistenceEnabled;\n\n- `\n ``\n ``\n `\n\n ### [persistenceCacheSizeBytes](#/c:objc(cs)FIRDatabase(py)persistenceCacheSizeBytes)\n\n `\n ` \n By default the Firebase Database client will use up to 10MB of disk space to\n cache data. If the cache grows beyond this size, the client will start\n removing data that hasn't been recently used. If you find that your\n application caches too little or too much data, call this method to change\n the cache size. This property must be set before creating your first\n `DatabaseReference` and only needs to be called once per application.\n\n Note that the specified cache size is only an approximation and the size on\n disk may temporarily exceed it at times. Cache sizes smaller than 1 MB or\n greater than 100 MB are not supported. \n\n #### Declaration\n\n Objective-C \n\n @property (nonatomic) NSUInteger persistenceCacheSizeBytes;\n\n- `\n ``\n ``\n `\n\n ### [callbackQueue](#/c:objc(cs)FIRDatabase(py)callbackQueue)\n\n `\n ` \n Sets the dispatch queue on which all events are raised. The default queue is\n the main queue.\n\n Note that this must be set before creating your first Database reference. \n\n #### Declaration\n\n Objective-C \n\n @property (nonatomic, strong) dispatch_queue_t _Nonnull callbackQueue;\n\n- `\n ``\n ``\n `\n\n ### [+setLoggingEnabled:](#/c:objc(cs)FIRDatabase(cm)setLoggingEnabled:)\n\n `\n ` \n Enables verbose diagnostic logging. \n\n #### Declaration\n\n Objective-C \n\n + (void)setLoggingEnabled:(BOOL)enabled;\n\n #### Parameters\n\n |-----------------|-------------------------------------------|\n | ` `*enabled*` ` | true to enable logging, false to disable. |\n\n- `\n ``\n ``\n `\n\n ### [+sdkVersion](#/c:objc(cs)FIRDatabase(cm)sdkVersion)\n\n `\n ` \n Retrieve the Firebase Database SDK version. \n\n #### Declaration\n\n Objective-C \n\n + (nonnull NSString *)sdkVersion;\n\n- `\n ``\n ``\n `\n\n ### [-useEmulatorWithHost:port:](#/c:objc(cs)FIRDatabase(im)useEmulatorWithHost:port:)\n\n `\n ` \n Configures the database to use an emulated backend instead of the default\n remote backend. \n\n #### Declaration\n\n Objective-C \n\n - (void)useEmulatorWithHost:(nonnull NSString *)host port:(NSInteger)port;"]]