1

I am getting an error "Cannot convert value of type '()' to expected argument type '[String : Any]'". I am trying to add data as a Codable struct to submit to firebase. However this error keeps popping up. Here is my code (in swift).

    do {
        try db.collection("users").document("i").setData(user)
    } catch {
        print(error)
    }

Here is the struct:

public struct User: Codable {
    var id: String
    var first_name: String
    var last_name: String
    var email: String

    enum CodingKeys: String, CodingKey {
        case id
        case first_name
        case last_name
        case email
    }
}

I have a feeling I am misunderstanding Codable but I am following tutorials exactly. I tried replacing user with ["user": user] nut that just crashes the app. Please help! I am following the firebase website example https://firebase.google.com/docs/firestore/manage-data/add-data

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I think that you should add the data as setData(from: user) instead of setData(user). Can you share with us a more complete example where we can see how you are structuring this user? – Chris32 Nov 16 '20 at 15:41

0 Answers0