I'm currently attempting to create a user database, with Firestore in Swift 5.
I have created a signup view controller, and I am following the Firestore documentation (this link), in order to store the user data.
In a constants file I have stored the following code.
struct userMap: Codable {
let firstName: String?
let lastName: String?
let email: String?
let profilePictureURL: String?
let UserIdentification: String?
enum CodingKeys: String, CodingKey {
case firstName
case lastName
case email
case profilePictureURL
case UserIdentification
}
}
And in my signup view controller, I have this code.
let user = Constants.userMap(firstName: firstName,
lastName: lastName,
email: email,
profilePictureURL: metaImageURL,
UserIdentification: docRefID)
do {
try dbRef.document(docRefID).setData(user)
} catch let error {
print("Error writing to Firestore: \(error)")
}
On the line try dbRef.document(docRefID).setData(user) I am getting the error, "Cannot convert value of type 'Constants.userMap' to expected argument type '[String : Any]' "
Something I feel is worth adding. In the firebase documentation, it recommends the below.
try dbRef.document(docRefID).setData(from: user)
But, I tried this, and this too and I was just asked to remove from:.
Thanks all for your help.