Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeMismatch "Not an array" #79

Open
kevinrenskers opened this issue Sep 23, 2019 · 4 comments
Open

typeMismatch "Not an array" #79

kevinrenskers opened this issue Sep 23, 2019 · 4 comments

Comments

@kevinrenskers
Copy link

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?

@gifffert
Copy link

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

@kevinrenskers
Copy link
Author

No :(

@mufumade
Copy link

mufumade commented Feb 26, 2020

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
Copy link

mufumade commented Feb 26, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants