Retrieve data from new Firebase

前端 未结 9 2861
醉梦人生
醉梦人生 2021-02-15 23:40

Please help. After migrating to new Firebase I can\'t retrieve data. Use this construction:

let ref = FIRDatabase.database().reference()

override func viewDidL         


        
9条回答
  •  [愿得一人]
    2021-02-16 00:30

    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.

提交回复
热议问题