13
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FirebaseのDatabaseで詰まったとこ

Last updated at Posted at 2016-08-09

CocoaPodsにインストールしたりjsonファイルを入れたりと、コンソールで指示されたことを一通りやったあと

ViewController.swift
import UIKit
import Firebase

class ViewController:UIViewController{

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

    override func viewDidLoad() {
        super.viewDidLoad()

みたいな感じに書こうとすると

Terminating app due to uncaught exception 'FIRAppNotConfigured', 
reason: 'Failed to get default FIRDatabase instance. 
Must call FIRApp.configure() before using FIRDatabase.'

というエラーが出てしまった。
FIRApp.configure()が呼ばれる前にFIRDatabaseを使おうとしてるのがいけないらしい

AppDelegate.swiftでFIRApp.configure()をdidFinishLaunchingWithOptionsに書いてたので

init()を追加して、その中に移すとちゃんと動いてくれた

AppDelegate.swift
    override init() {
         super.init()
         FIRApp.configure()
    }

13
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?