Alex Alex - 1 year ago 82
iOS Question

Swift + Firebase simulated login error

iOS rookie here struggling through the early stages of an app that was initially led by a mentor. Issue at the moment occurs in the login view controller:

override func viewDidAppear(animated: Bool) {
let myRootRef = Firebase(url:"")
if myRootRef.authData.uid != nil {
self.performSegueWithIdentifier("loginToGreet", sender: nil)


Error message beside the second to last line reads "Thread 1: EXC_BAD_INSTRUCTION and below reads "fatal error: unexpectedly found nil while unwrapping an Optional value(lldb)"

This was working when we initially put the project on the shelf. The next chunk of code, if it matters:

@IBAction func loginPress(sender: UIButton) {
let myRootRef = Firebase(url:"")
myRootRef.authUser(self.patientLoginName.text, password:self.patientLoginPassword.text,
withCompletionBlock: { error, authData in
if error != nil {
// There was an error logging in to this account
} else {
// We are now logged in
self.performSegueWithIdentifier("loginToGreet", sender: nil)

Answer Source


  if myRootRef.authData != nil {
     self.performSegueWithIdentifier("loginToGreet", sender: nil)

authData might be nil and you are checking for authData.uid. Since authData is nil it will crash at the uid access so change your error checking like above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download