I am trying to save user information in FireBaseFirestore
, the function I am using is from the Firestore
documentation. I Am getting that error but the app is running fine and the data is saved correctly.
CodePudding user response:
You have to convert your UserModel
to [String : Any]
type in order to save it on firebase. Try this:
func convertUserModelToDictionary(user: UserModel) -> [String : Any] {
let userData = [
"name" : user.name, // change these according to you model
"email": user.email,
"user_id": user.userId
]
return userData
}
You can use this function as:
do {
let userData = convertUserModelToDictionary(user: userInfo)
try db.collection("usersInformations").document(userInfo.id).setData(from: userData)
} catch let error {
print(error.localizedDescription)
}