【发布时间】:2020-09-03 21:05:26
【问题描述】:
我在注册后尝试展示一个视图控制器,但我不断收到错误
线程 1:致命错误:在隐式中意外发现 nil 展开可选值
我正在使用 Firebase,但我不知道这是否与它有关。
Auth.auth().createUser(withEmail: email, password: password, completion: {(user, error) in
guard error == nil else{
AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
return
}
guard let user = user else { return }
print(user.user.email ?? "Missing Email")
print(user.user.uid)
let changeRequest = user.user.createProfileChangeRequest()
changeRequest.displayName = username
changeRequest.commitChanges(completion: { (error) in
guard error == nil else{
AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
return
}
let homePage = HomeView()
self.present(homePage, animated: true, completion: nil)
})
})
这是我得到错误的地方:
let homePage = HomeView()
self.present(homePage, animated: true, completion: nil)
对于我尝试呈现的关于用户名的视图控制器,我也遇到了同样的错误 这是该视图控制器的代码:
override func viewDidLoad() {
super.viewDidLoad()
guard let username = Auth.auth().currentUser?.displayName else {return}
welcome.text = "Hello \(username)"
welcome.textColor = UIColor.systemGreen
这是发生错误的地方:
welcome.text = "你好(用户名)"
【问题讨论】:
-
当它崩溃时,你能打印出
welcome是什么吗?您的网点可能未设置。 -
您是否将 welcome 标签连接到情节提要中的 UILabel。如果你没有连接 api 因为 nil 而崩溃 welcome
-
我确实将欢迎标签连接到情节提要中的 UILabel,但它仍然无法正常工作。
-
我还确保删除任何潜在的重复项,但即便如此它也无法正常工作
-
清理构建你的代码...检查欢迎连接
标签: swift xcode firebase fatal-error