I am trying to present a view controller after I sign up but I keep getting the error
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
I am using Firebase, but I don't know if this anything to do with it.
Auth.auth().createUser(withEmail: email, password: password, completion: {(user, error) in
guard error == nil else{
AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
return
}
guard let user = user else { return }
print(user.user.email ?? "Missing Email")
print(user.user.uid)
let changeRequest = user.user.createProfileChangeRequest()
changeRequest.displayName = username
changeRequest.commitChanges(completion: { (error) in
guard error == nil else{
AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
return
}
let homePage = HomeView()
self.present(homePage, animated: true, completion: nil)
})
})
This is where I get the error:
let homePage = HomeView()
self.present(homePage, animated: true, completion: nil)
I also get the same error for the view controller I am trying to present regarding the username This is the code from that view controller:
override func viewDidLoad() {
super.viewDidLoad()
guard let username = Auth.auth().currentUser?.displayName else {return}
welcome.text = "Hello \(username)"
welcome.textColor = UIColor.systemGreen
This is where the error occurs:
welcome.text = "Hello (username)"