I made an extension to UIViewController and inside i have function I use several times:
extension UIViewController {
func transitionToHomeVC() {
let homeViewController = self.storyboard?.instantiateViewController(withIdentifier: NameConstants.StoryBoard.homeViewController) as? HomeViewController
self.view.window?.rootViewController = homeViewController
self.view.window?.makeKeyAndVisible()
}
}
And I have a registration button and as soon as you click if the information was received and correct and etc ... then he has to move me at the to the HomeViewController screen and he does not do it. He does all the actions but does not pass to screen.
@IBAction func signUpTapped(_ sender: Any) {
// Validate the fields
let error = validDataFields()
if error != nil {
// There's something wrong with the fields, show error message
Service.showError(vc: self, message: error!)
}
else {
// Create cleaned versions of the data
let fireName = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let lastName = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
// Create the user
Auth.auth().createUser(withEmail: email, password: password) { resulte, err in
// Check for errors
if err != nil {
// There was an error creating the user
Service.showError(vc: self, message: "Error creating user \n make sure you enter: \n current email")
}
else {
// User was created successfully, now store the first name and last name
let db = Firestore.firestore()
db.collection("users").addDocument(data: ["firstName":fireName,"lastName":lastName, "uid": resulte!.user.uid]) { error in
if error != nil {
// Show error message
Service.showError(vc: self, message: " Error saving user Data")
}
}
self.transitionToHomeVC()
}
}
}
}
why it not move to homeViewController?