Joseph
Joseph

Reputation: 23

Swift Error Message with a Firebase completion block

I'm getting an error from this code. Is there any way anyone could fix this problem?

enter image description here

Upvotes: 2

Views: 156

Answers (1)

pinedax
pinedax

Reputation: 9356

change it to this:

    FIRAuth.auth()?.signInAnonymously(completion: { (anonymousUser, error) in

        if error == nil{
            print("UserId : \(anonymousUser?.uid)")
        }else{
            print(error?.localizedDescription)
        }

    })

Note: You could change your if statement to something like:

    FIRAuth.auth()?.signInAnonymously(completion: { (anonymousUser, error) in

        if let err = error{
            print(err.localizedDescription)
            return
        }

        print("UserId : \(anonymousUser?.uid)")

    })

To save you an else and make your code more readable.

Upvotes: 3

Related Questions