我在此代码中收到以下错误: 变量在其自己的初始值(Swift和Xcode 9 beta)中使用
我通过以下代码在第82行抛出此错误: 让值= [“用户名”:用户名,“电子邮件”:电子邮件,“图片”:“”]
有人可以帮我弄清楚为什么我会收到这个错误吗?
import UIKit
import Firebase
class ViewController: UIViewController {
@IBOutlet weak var username: UITextField!
@IBOutlet weak var email: UITextField!
@IBOutlet weak var password: UITextField!
func signup(){
guard let username = username.text else{
print("username issue")
return
guard let email = email.text else{
print("e-mail issue")
return
}
guard let password = password.text else{
print("password issue")
return
}
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
if error != nil{
print(error!)
return
}
guard let uid = user?.uid else {
return
}
let userReference = self.databaseRef.child("users").child(uid)
let values = ["username": username, "email": email, "pic":""]
userReference.updateChildValues(values
, withCompletionBlock: { (error, ref) in
if error != nil{
print(error)
return
}
self.dismiss(animated: true, completetion: nil)
})
}
}
}
答案 0 :(得分:0)
我相信你错过了一个结束"}"在注册函数的第一个保护声明中。