Mariah Mariah - 2 months ago 91
Swift Question

Converting to Swift 3 (Swift and Firebase Project)

I have just updated my Xcode to Xcode8 and I have converted the project to swift 3.

In signIn function here:

Firth. Auth()?.signIn(withEmail: self.EmailTF.text!, password: self.PasswordTF.text!, completion: { (user: FIRUser?, error: NSError?) in
if let error = error {
print(error.localizedDescription)
} else {

self.ref.child("UserProfile").child(user!.uid).setValue([
"email": self.EmailTF.text!,
"name" : self.NameTF.text!,
"phone": self.PhoneTF.text!,
"city" : self.CityTF.text!,
])
print("Sucess")

}
})


I'm getting this error:

cannot convert value of type '(FIRUser?, NSError?) -> ()' to expected argument type 'FIRAuthResultCallback?'


What's the replacement of it in swift 3?

Answer

Just replace it with :-

 FIRAuth.auth()?.signIn(withEmail:self.EmailTF.text!, password: self.PasswordTF.text!, completion: { (user, err) in
       if let error = err {
                        print(error.localizedDescription)
                    } else {

                       self.ref.child("UserProfile").child(user!.uid).setValue([
                            "email": self.EmailTF.text!,
                            "name" : self.NameTF.text!,
                            "phone": self.PhoneTF.text!,
                            "city" : self.CityTF.text!,
                            ])
                        print("Sucess")

                    }
    })