I tried literally tried every possible option to write it, but I can't seem to figure out the solution.
func signup(email: String, password: String) {
Auth.auth().createUser(withEmail: emailText.text!, password: passwordText.text!, completion: { (user, error) in
if error != nil {
print(error!)
}else {
self.createProfile(user!) //Here's the problem described in the title //
let homePVC = RootPageViewController()
self.present(homePVC, animated: true, completion: nil)
}
})
}
func createProfile(_ user: User) {
let newUser = ["email": user.email, "photo": "https://firebasestorage.googleapis.com/v0/b/ecoapp2.appspot.com/o/photos-1.jpg?alt=media&token=ee104f2d-ed9a-4913-8664-04fd53ead857"]
self.databaseRef.child("profile").child(user.uid).updateChildValues(newUser) { (error, ref) in
if error != nil {
print(error!)
return
}
print("Profile successfully created")
}
}
Starting from Firebase API 5.0 it's createUser() method returns FIRAuthDataResultCallback instead of User object directly.
In your case you can fix it my making following changes:
For more code readability I would replace your code like below:
You need