-1
@IBAction func login(_ sender: Any) {
    guard emailField.text != "", passField.text != "" else {return}

    Auth.auth().signIn(withEmail:emailField.text!,password:passField.text!, completion: { (user, error) in
        if let error = error {
            print(error.localizedDescription)

I get this error:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
onur
  • 1
  • 2

1 Answers1

0

Try:

    guard let email = self.emailField.text, let password = self.passField.text else { return }
    if email != "" && pass != "" {
        Auth.auth().signIn(withEmail: email, password: password) { (user, err) in
            if err != nil { print(err.localizedDescription); return }

            // do something

        }
    }
Daniel Dramond
  • 1,538
  • 2
  • 15
  • 26
  • Sorry but i did like above so I got the same error. I dont know where is my fault. I checked all other the same error stuation however none of them solve my problem. I nearly crazy. Please help me – onur May 22 '18 at 09:07
  • @onur Unfortunately it doesn't look like that's where the error is. You might want to add a bunch of breakpoints in your code to see roughly where about the code crashes. For example, if you add break points in the code above and it hits those and moves to breakpoints AFTER it, it clearly isn't the code above that is the issue. Hope this helps – Daniel Dramond May 22 '18 at 09:09