CodableFirebase icon indicating copy to clipboard operation
CodableFirebase copied to clipboard

typeMismatch "Not an array"

Open kevinrenskers opened this issue 6 years ago • 4 comments

I have a model where one of the properties is a dictionary like this:

struct MyModel: Codable {
  let userIds: [String: Bool]
}

This works fine, it decodes and encodes just fine. However, I want to use the https://github.com/pointfreeco/swift-tagged to add type-safety to my models instead of using strings everywhere. That also means that I want to change the above model to something like this:

struct MyModel: Codable {
  let userIds: [User.Id: Bool]
}

Even though that should work just fine with Codable, I am getting this error:

typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "matchedUserIds", intValue: nil)], debugDescription: "Not an array", underlyingError: nil))

Not sure why it's looking for an array?

kevinrenskers avatar Sep 23 '19 17:09 kevinrenskers

Plus. Also ran into this problem. Do you find answer?

gifffert avatar Oct 10 '19 02:10 gifffert

No :(

kevinrenskers avatar Oct 10 '19 08:10 kevinrenskers

Also ran into this problem :( For me in the main struct i added a sub struct. Both are conforming to the Codable protocol.

struct MainStruct:Codable{ let name:String let someInfo: SubStruct }

Throws the following error: typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "SomeValue", intValue: nil), CodingKeys(stringValue: "SomeOtherValue", intValue: nil)], debugDescription: "Not an array", underlyingError: nil))

"SomeValue" and "SomeOtherValue" are vars within the SubStruct

mufumade avatar Feb 26 '20 22:02 mufumade

Okay Sorry :/ My fault. I typed FirebaseDecoder instead of FirestoreDecoder

It would be nice if there was a little note in the error message if that's feasible.

It may be better if FirebaseDecoder is renamed to something like RealtimeDBDecoder

mufumade avatar Feb 26 '20 23:02 mufumade