-
Notifications
You must be signed in to change notification settings - Fork 91
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
Decoding Arrays results in type mismatch #51
Comments
I have no idea how this library works exactly, plus I'm just a passenger on this repo, but the above snapshot which is like a json does not work as an array. The
Instead it should be:
Therefore the following 'might' work:
|
@DevAndArtist So Firebase does not allow values to be arrays; everything must be a dictionary. Otherwise I would have designed the data model according to your response. Instead to solve this, I simply pass the 'values' of the dictionary / snapshot.value to the decoding function:
The magic is in passing Array(value.values) instead of just value |
Ah sorry, you were referring to the old database, while I had Firestore in mind when I wrote my reply which does support arrays and maps. |
@vikdenic Firebase does allow array as values. You can save a NSArray to the firebase. Try it in some test project |
Also read https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html for some of the rationale in Google's choice. |
My data structure looks like this. "humans" is a dictionary of keys whose values are the dictionary of a human. And that human can have a dictionary of keys whose values are the dictionary of a dog.
And so my Swift structs looks like this to match it:
I try to decode like this:
let human = try FirebaseDecoder().decode([Human].self, from: value)
But I am getting the following error when trying to encode objects that have arrays of some object:
typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Not an array", underlyingError: nil))
How can I properly encode a dictionary's values as an array?
The text was updated successfully, but these errors were encountered: