-1
Swiftのコードに問題がある エラーが発生した場合は、verifyInputメソッドはfalseを返します。 何があっても常にtrueを返します。しかし、そのわずか真メソッドは変数を変更せずに返す
を返す問題がverifyInput
がregister
から同期的に呼び出されていることですが、それが完了ブロックとAuth.auth().createUser
への非同期呼び出しです内
@IBAction func register(_ sender: UIButton) {
let check = verifyInput(email :email.text! ,password: password.text!)
if(check==true){
self.performSegue(withIdentifier: "goToAmazon", sender: nil)
} else if(check==false) {
self.message.text = "Sorry! there's an error"
}
}
func verifyInput(email: String, password: String) -> Bool {
var check = true
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
if error != nil {
print("error")
check = false
} else if(error==nil){
check = true
print("registered!")
}
}
return check
}
は、非同期API呼び出しのいくつかの研究を行います。これを読んで – rmaddy
は、あなたがよりhttps://stackoverflow.com/questions/748175/asynchronous-vs-synchronous-execution-what-does-it-really-mean –