您如何在自定义 class 中使用 Firebase?

How do you use Firebase within a custom class?

我完成了在我的应用程序上设置 Firebase 的步骤,并且测试效果很好。但是当我创建自定义 swift class 来创建管理数据库的函数时,它崩溃并显示 "failed to get default firdatabase instance. must call firapp.configure() before using firdatabase"。我在 AppDelegate 中调用了 configure(),但它似乎没有传递到我的自定义 class。下面是我得到的错误,我在 AppDelegate 中调用 FirebaseApp.configure() 的部分,以及自定义的 class。提前致谢。

DatabaseTestApp[7814:336288] *** 由于未捕获的异常 'FIRAppNotConfigured' 而终止应用程序,原因:'Failed to get default FIRDatabase instance. Must call FIRApp.configure() before using FIRDatabase.'

import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    return true
    }
}

我的习惯class:

import Foundation
import UIKit
import FirebaseDatabase
class FirebaseClass
{
    var ref:DatabaseReference?
    init ()
    {
        ref = Database.database().reference()
    }
}

假设您正在创建某种名为 FirebaseManager 的 class,请执行以下操作:

class FirebaseManager {
    public static let instance = FirebaseManager()
    private init(){
        FirebaseApp.configure()
    }
}