我是swift和firebase的新手。但我会尝试同时使用Firebase进行Google登录和电子邮件/密码身份验证。我得到错误:预期的声明。希望有人能帮助我。在我将Google登录代码添加到Xcode之前,它工作正常。
var currenUser: User?
class ViewController: UIViewController, UITextFieldDelegate, GIDSignInUIDelegate {
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet var collectionTextField: [UITextField]!
var dbRef: DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
// Google login
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signIn()
}
dbRef = Database.database().reference()
for textField in self.collectionTextField {
textField.delegate = self
}
func loginAction(_ sender: Any) {
Auth.auth().signIn(withEmail: self.emailTextField.text!, password: self.passwordTextField.text!, completion: {
(user, error) in
if let error = error {
print("Sign in error: \(error.localizedDescription)")
return
}
self.dbRef.child("usersID").child(user!.uid).child("info").setValue(["email": user!.email])
print("user logged in: \(String(describing: user?.displayName))")
self.performSegue(withIdentifier: "SignIn", sender: nil)
})
}
答案 0 :(得分:0)
看起来代码在任何函数之外定义dbRef
。也许你打算把这些代码放在viewDidLoad()
?
override func viewDidLoad() {
super.viewDidLoad()
// Google login
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signIn()
dbRef = Database.database().reference()
for textField in self.collectionTextField {
textField.delegate = self
}
}