If I am correct: EXC_BAD_INSTRUCTION means that the app crashed because something does not exists. (After googling it and trying to get my head round it)
However I am getting the error:
Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
When I tried and load another view.
This is the function where the app crashes:
func loginUserNeedsEmailVerification() {
let next = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
next.isUserLoggedInButNeedsEmail = true
self.present(next, animated: true, completion: nil)
}
I am calling this function. From another function like so:
perform(#selector(loginUserNeedsEmailVerification), with: nil, afterDelay: 0)
Even though the file exists, I changed the ! to ? like so:
let next = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController
next?.isUserLoggedInButNeedsEmail = true
self.present(next?, animated: true, completion: nil)
Then another error thrown at the last line:
Value of optional type is not unwrapped.
When I click the little fix it. It changed the code to this:
self.present((next?)!, animated: true, completion: nil)
But then that also errors like so:
optional chain has no effect
What am I doing wrong, and how do I fix this?