You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way some data stored in Firebase Database is converted into Swift objects is unconsistent.
Steps to reproduce:
For example, i have data stored in Firebase Database like this (JSON)
"test-dict": {
"2": true,
"3": true,
"4": true
},
when i am trying to cast this in Swift to Dictionary [String: Any] or [String: Bool] it always fails.
the actual type in swift for this will be Array [Any]
particular for this example the array will be: [NSNull, NSNull, Bool, Bool, Bool]
This is the intended behavior as the Realtime Database coerces objects with numerical keys to arrays. Specifically, "... if all of the keys are integers, and more than half of the keys between 0 and the maximum key in the object have non-empty values, then Firebase clients will render it as an array." Once you introduce a non-numerical key, the clients know it's an object again.
In practice, that's why you're seeing: [NSNull, NSNull, Bool, Bool, Bool]. The Database treats it as:
The problem
The way some data stored in Firebase Database is converted into Swift objects is unconsistent.
Steps to reproduce:
For example, i have data stored in Firebase Database like this (JSON)
when i am trying to cast this in Swift to Dictionary
[String: Any]
or[String: Bool]
it always fails.the actual type in swift for this will be Array
[Any]
particular for this example the array will be:
[NSNull, NSNull, Bool, Bool, Bool]
but when we add another literal key to the dict:
it successfully casts to [String: Any] or [String: Bool]
Was this behaviour supposed to be so or is it an issue?
The text was updated successfully, but these errors were encountered: