Please help. After migrating to new Firebase I can\'t retrieve data. Use this construction:
let ref = FIRDatabase.database().reference()
override func viewDidL
So, with mine, I also had a ref being declared immediately when the view controller was instantiated. I had to make it load after the app had been configured in the app delegate with FIRApp.configure()
.
Before:
let serverRef = Firebase("firebaseURL")
After:
lazy var serverRef = FIRDatabase.database().reference()
This delays the instantiation of the database reference until its needed, which wont be until viewDidLoad
on your initial view controller.
In my case I had to change the configure to be called before calling the super applicationDidLaunch:
[FIRApp configure];
[super application:application didFinishLaunchingWithOptions:launchOptions];
I too had a problem with the Firebase Database. Fixed it by adding
import FirebaseDatabase
to my code
To build on the answer given by @ColdLogic, the reason I had this error was because I had my Firebase database reference being created in an init method on a view controller, not in the viewDidLoad method. Since the init methods for all classes that are instantiated when the app launches are called before the application:DidFinishLaunchingWithOptions method in the AppDelegate, it was causing this crash. Moving this line of code:
class MyViewController {
var firebaseRef: FIRDatabaseReference
required init?(coder aDecoder: NSCoder) {
...
firebaseRef = FIRDatabase.database().reference()
}
override func viewDidLoad() {
...
}
}
to here:
class MyViewController {
var firebaseRef: FIRDatabaseReference
required init?(coder aDecoder: NSCoder) {
...
}
override func viewDidLoad() {
...
self.firebaseRef = FIRDatabase.database().reference()
}
}
solved the problem for me.
Had the same problem. I looked for linking problems that are related to the plist but that wasn't the problem. I thought maybe it has caused because of that my initial view controller is revoked before the configurations are completed. I solved the problem by experimenting a bit.
My initial view controller was this:
let ref = FIRDatabase.database().reference()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
I've changed that to this:
var ref = FIRDatabaseReference.init()
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
// Do any additional setup after loading the view, typically from a nib.
}
Crash resolved.
I didn't see this answer yet, I had to add the configure call to the AppDelegate init method. So it looks like:
override init() {
super.init()
// Firebase Init
FIRApp.configure()
}