I am following instructions for installation and setup of realtime database on iOS app from this link
and I am confused where to add the statement
self.ref = FIRDatabase.database().reference()
in my app in xcode. Which file or location?
You can reference the root or child location in your Database by calling firebase. database(). ref() or firebase. database().
Go to the Firebase console. In the center of the project overview page, click the iOS+ icon to launch the setup workflow. If you've already added an app to your Firebase project, click Add app to display the platform options. Enter your app's bundle ID in the bundle ID field.
References are lightweight, so you can create as many as you need, and they are also reusable for multiple operations. To create a reference, get an instance of the Storage service using getStorage() then call ref() with the service as an argument. This reference points to the root of your Cloud Storage bucket.
Go to Database section. Tap Cloud Firebase (marked 1 in picture) and select Realtime Database. Marked 2 is the URL.
Firebase 4.0 and later: Make sure you add the following to Podfile! I had the same problem as you until I added this (found on the previous page of the Firebase setup tutorial).
pod 'Firebase/Database'
If you're like me, you ignored it because you thought you already added this line in the Firebase setup tutorial, but the line added in setup is:
pod 'Firebase/Core'
After you add that, it should work. A generic view controller would look like the following:
import Firebase
import FirebaseDatabase
class GenericViewController: UITableViewController {
var ref: DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
ref = Database.database().reference()
}
}
This had me stuck for a while - I hope this helps! :)
Below is the code.
import UIKit
import Firebase
import FirebaseAuthUI
class ExampleVC: UIViewController, UINavigationControllerDelegate {
var ref: FIRDatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
//if user is signed in
configureDatabase()
}
func configureDatabase() {
//Gets a FIRDatabaseReference for the root of your Firebase Database.
ref = FIRDatabase.database().reference()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With