我跟随Rob Percival的iOS开发者课程,目前我正在坚持使用Uber克隆"项目。以下是有问题的代码的摘录。发生错误的代码行是:
if user?.displayName == "Lehrer" {
在评论//LOG IN
@IBAction func topTapped(_ sender: Any) {
if emailTextField.text == "" || passwordTextField.text == "" {
displayAlert(title: "Achtung", message: "Du musst sowohl eine Email-Adresse als auch Passwort eingeben!")
} else {
if let email = emailTextField.text {
if let password = passwordTextField.text {
if signUpMode {
// SIGN UP
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
self.displayAlert(title: "Error", message: error!.localizedDescription)
} else {
if self.benutzerLehrerSwitch.isOn {
//Lehrer
let req = Auth.auth().currentUser?.createProfileChangeRequest()
req?.displayName = "Lehrer"
req?.commitChanges(completion: nil)
self.performSegue(withIdentifier: "lehrerSegue", sender: nil)
} else {
// RIDER
let req = Auth.auth().currentUser?.createProfileChangeRequest()
req?.displayName = "Benutzer"
req?.commitChanges(completion: nil)
self.performSegue(withIdentifier: "benutzerSegue", sender: nil)
}
}
})
} else {
// LOG IN
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
self.displayAlert(title: "Error", message: error!.localizedDescription)
} else {
if user?.displayName == "Lehrer" {
// BENUTZER
self.performSegue(withIdentifier: "benutzerSegue", sender: nil)
} else {
// LEHRER
self.performSegue(withIdentifier: "lehrerSegue", sender: nil)
}
}
})
}
}
}
}
}
基本上,我允许用户注册为两种不同类型的角色之一(" Lehrer"或" Benutzer")并根据他们选择的那些,他们应该看到登录后不同的屏幕。我使用Firebase作为此代码的后端,如果我删除了错误的代码,注册用户的帐户就可以正常工作。有没有人有任何想法?
您可以在此屏幕截图中看到完整的外观:
答案 0 :(得分:4)
Google已在Firebase 5+更新后更新了这些方法 试试这个
self.name = user.user. displayName
答案 1 :(得分:2)
将user?.user.displayName
代替user?.displayName