我最近一直在设计带有firebase的IOS应用程序。它应该是一个消息应用程序。我设法使用Facebook登录和电子邮件登录来验证身份验证过程。当我使用Facebook登录时,我还能够将用户个人资料页面信息保存到firebase数据库中,并且能够从firebase检索该数据并将其呈现给应用程序。但是,当我尝试使用电子邮件登录检索相同的数据时,应用程序崩溃了。它显示了一个线程1:信号SIGABRT错误。控制台消息是
由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [NSNull objectForKey:]:无法识别的选择器发送到实例0x110c70cf0
这里有以下代码:
覆盖func viewDidLoad(){ super.viewDidLoad()
let userSignedIn = Auth.auth().currentUser
// to retrieve user info from firebase and show it on app profile page
var refHandle = self.ref.child("users").observe(DataEventType.value, with: { (snapshot) in
let usersDict = snapshot.value as? NSDictionary
print(usersDict)
let userDetails = usersDict?.object(forKey: self.user!.uid)
print(userDetails)
if self.ageTextfield.placeholder?.lowercased() == "age" {
self.ageTextfield.text = (userDetails as AnyObject).object(forKey: "age") as! String
}
if self.sexTextfield.placeholder?.lowercased() == "sex" {
self.sexTextfield.text = (userDetails as AnyObject).object(forKey: "sex") as! String
}
if self.nameTextfield.placeholder?.lowercased() == "name" {
self.nameTextfield.text = (userDetails as AnyObject).object(forKey: "name") as! String
}
if self.occupationTextfield.placeholder?.lowercased() == "occupation" {
self.occupationTextfield.text = (userDetails as AnyObject).object(forKey: "occupation") as! String
}
if self.hobbiesTextview.text.lowercased() == "hobbies" {
self.hobbiesTextview.text = (userDetails as AnyObject).object(forKey: "hobbies") as! String
}
})
我使用异常断点,并突出显示以下行:
self.ageTextfield.text = (userDetails as AnyObject).object(forKey: "age") as! String
请让我知道我做错了什么。