Firebase Realtime Database is available on all Apple platforms, including iOS, macOS, macOS Catalyst, tvOS, and watchOS. It is not available for App Clips. The setup instructions in this page reference iOS in specific examples, but are generic and work for any Apple platform target.
Create a Database
Navigate to the Realtime Database section of the Firebase console. You'll be prompted to select an existing Firebase project. Follow the database creation workflow.
Select a starting mode for your Firebase Security Rules:
- Test mode
Good for getting started with the mobile and web client libraries, but allows anyone to read and overwrite your data. After testing, make sure to review the Understand Firebase Realtime Database Rules section.
To get started with the web, Apple, or Android SDK, select testmode.
- Locked mode
Denies all reads and writes from mobile and web clients. Your authenticated application servers can still access your database.
Choose a location for the database.
Depending on the location of the database, the URL for the new database will be in one of the following forms:
(for databases in
(for databases in all other locations)
When you enable Realtime Database, it also enables the API in the Cloud API Manager.
Add Firebase Realtime Database to your app
Use Swift Package Manager to install and manage Firebase dependencies.
- In Xcode, with your app project open, navigate to File > Add Packages.
- When prompted, add the Firebase Apple platforms SDK repository:
- Choose the Realtime Database library.
- When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.
Configure Realtime Database Rules
The Realtime Database provides a declarative rules language that allows you to define how your data should be structured, how it should be indexed, and when your data can be read from and written to.
Set up Firebase Realtime Database
You must initialize Firebase before any Firebase app reference is created or used. If you have already done this for another Firebase feature, you can skip this step.
- Import the
FirebaseCoremodule in your
UIApplicationDelegate, as well as any other Firebase modules your app delegate uses. For example, to use Cloud Firestore and Authentication:
import FirebaseCore import FirebaseFirestore import FirebaseAuth // ...
@import FirebaseCore; @import FirebaseFirestore; @import FirebaseAuth; // ...
- Configure a
FirebaseAppshared instance in your app delegate's
// Use Firebase library to configure APIs FirebaseApp.configure()
// Use Firebase library to configure APIs [FIRApp configure];
- Create a reference to your database and specify the location you want to
SwiftNote: This Firebase product is not available on the App Clip target.
var ref: DatabaseReference! ref = Database.database().reference()
Objective-CNote: This Firebase product is not available on the App Clip target.
@property (strong, nonatomic) FIRDatabaseReference *ref; self.ref = [[FIRDatabase database] reference];
Learn how to structure data for Realtime Database.
Prepare to launch your app:
Enable App Check to help ensure that only your apps can access your databases.
Set up budget alerts for your project in the Google Cloud Console.
Monitor the Usage and billing dashboard in the Firebase console to get an overall picture of your project's usage across multiple Firebase services. You can also visit the Realtime Database Usage dashboard for more detailed usage information.
Review the Firebase launch checklist.