gpt4 book ai didi

ios - Firebase 和线程 1

转载 作者:行者123 更新时间:2023-11-28 06:28:23 27 4
gpt4 key购买 nike

每当我添加我的 firebase 代码时,我都会获得自主权:

class AppDelegate: UIResponder, UIApplicationDelegate {      THREAD 1 SIGNAL SGABRT

我已经从 View Controller 脚本中取出所有与 Firebase 相关的代码,它运行顺利,没有错误。我正在使用 swift 3 并尝试更新我的 pod,但也没有成功。这是我确定必须导致错误的代码。

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

那是在我的脚本和我所有其他声明的开头。还有……

        ref.child("Agent1").observeSingleEvent(of: .value, with: { (snapshot) in

let value = snapshot.value as? NSDictionary
self.FnameA1 = value?["Fname"] as? String ?? ""
print("\(self.FnameA1)")

}) { (error) in
print(error.localizedDescription)
}

这是我尝试从数据库中获取数据并将本地变量 (FnameA1) 设置为数据库中的字符串的地方。虽然我在编译时没有出错,但我知道错误一定在那里。我将在下面显示我的数据库的格式,以防错误来 self 从中获取数据的方式。

{
"Agent1" : {
"Edition" : "Standard 17",
"Fname" : "L.",
"Lname" : "James",
"Ovr" : 95,
"Pos" : 3,
"Price" : 1000000
}
}

最佳答案

您收到此错误是因为您在配置 Firebase 之前尝试使用 de Firebase 引用。在您的日志中,您应该会看到类似这样的消息:

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

您可以通过先创建变量,然后再设置值(实际引用)来解决此问题。

var ref : FIRDatabaseReference?

然后在你的函数中:

ref = FIRDatabase.database().reference()
ref.child("Agent1").observeSingleEvent(of: .value, with: { (snapshot) in

let value = snapshot.value as? NSDictionary
self.FnameA1 = value?["Fname"] as? String ?? ""
print("\(self.FnameA1)")

关于ios - Firebase 和线程 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41082729/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com