lundi 15 mars 2021

Else statement triggers twice in Swift

I've been trying to register a user to Firebase and while doing that I'm checking if there is an error. If error occurs, then my code block pops up a UIalertcontroller and prints "error" once So far it works fine.

When there is no error then it should do a segue and print "segue done". But While it has no error the code triggers segue twice and prints "segue done" twice. Why this happens?

`  @IBAction func registerButton(_ sender: Any) {
    
            
            firestoreManager.registerUser(mail: mailField.text!, fullName: fullNameField.text!, username: usernameField.text!, password: passwordField.text!, instruments: instrumentArray, registerUserError: { [self] (canRegister) in
                if canRegister == false {
                    print("registeruserfail")
                    
                    let alert = UIAlertController(title: "Error", message: firestoreManager.errorString, preferredStyle: .alert)
                    self.present(alert, animated: false) {
                        alert.message = firestoreManager.errorString
                        alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
                        print("error")
                    }
                }
                else { // this statement triggers twice

                    performSegue(withIdentifier: "toMainPage", sender: self)
                    print("segue done")
                    return
                }
            })
        
        
    
    
    
}`

Aucun commentaire:

Enregistrer un commentaire