I just upgraded the pod file on my Xcode project for Firebase and it displayed a bunch of errors. When signing up a user I get the error Cannot convert value type "User?" to expected argument type "User!"
I'm not sure what the problem is. I tried changing some of the optional values to get it working, but I do not seem to understand well what the issue is.
Here's the function where I have the error:
The code has been modified with the solution to my issue
import Firebase
// Sign Up Function
func signUp(username: String, name: String, email: String, password: String){
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
self.setUserInfo(user: user, username: username, name: name, email: email, password: password)
}
else{
print(error?.localizedDescription as Any)
}
})
}
// Set the user info to Firebase storage. username, and password
private func setUserInfo(user: Firebase.User!, username: String, name: String, email: String, password: String){
if error == nil {
self.saveUserInfo(user: user, username: username, name: name, password: password)
}
else{
print(error?.localizedDescription as Any)
}
}
EDIT:
As user ryanwils mentioned, wherever I use FIRUser
needed to be replaced with Firebase.User
Here's a link to the Migration guide that explained this a little bit further: https://firebase.google.com/docs/reference/ios/naming-migration-guide
Note that the code has been updated so no errors are given as of the day of this edit
The new Firebase version dropped the FIR
prefix on most types so now FIRUser
is called User
. Do you already have a User
struct or class in your app? If so, you'll need to change the parameter in thesetUserInfo
call should accept a Firebase.User
(notice no !
), not User!
.
Then, when you're calling it you can either grab it with if let
, guard let
or force unwrap it with user!
as you pass it in.
Let me know if that's not the case and I can try to help further!
Edit: Including a link to the Firebase 4 Swift Migration Guide that explains all the changes necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With