As with other features in Firebase, to include the database functionality your app much have the correct CocoaPod installed. Also, the Firebase console is used to set the configuration of your project to include the Realtime Database for online storage. From there the Framework can be included and used in your app.
- [Instructor] Now we're gonna switch gears a bit and we're gonna talk about Firebase's Realtime Database. This is the database that for a long time was synonymous with Firebase. To add support for Firebase Realtime Database in our project we need to add another CocoaPod: the Firebase/Database Cocoapod. From there we'll be able to create a database reference that they call Database.database.reference. Once we have that, we'll have access to be able to create, read, update, and delete our data online.
By default all of your users will have read/write permission to the database. This is something that can be changed to the console but is outside the scope of this course. The first thing we'll do is add the new CocoaPod to our workspace. Going back to the terminal, we'll edit the pod file again with vi Podfile. Down at the bottom of our list of pods, we'll add a new one, pod 'Firebase/Database'. Save this file, and once again call pod Install.
This will install the CocoaPod to support the realtime database in our project. Now that we have that we can get the reference to it in Xcode. Going back to our View Controller, we're gonna add an additional property. This'll be the reference to our database. On line 24 I'll type var ref, and it will be of type DatabaseReference. It's an optional. In our viewDidLoad, we'll set it equal to the database reference itself.
On line 34 I'll type ref = Database.database().reference. Now I've got a reference to the database that we'll use going forward to create, read, update, and delete our data. Next we'll look at the structure of the data as it's stored in Firebase's Realtime Database. To prepare your project for supporting the Firebase Realtime Database, you need to install the pod for Firebase/Database.
Once that's in your code you can get a reference to the database, and remember, by default, all of your users have read/write permission.
- Creating a new project and app
- Installing Firebase CocoaPods
- Configuring authentication with Firebase
- Building the Firebase authentication UI
- Configuring data storage with Firebase Realtime Database
- Storing files in Cloud Storage
- Working with data from Firestore