Single integer as key in firebase (Firebase array behavior)

前端 未结 4 1213
粉色の甜心
粉色の甜心 2021-02-10 21:58

If I insert data into node/a/0 in firebase.

the result will treat a is an array a[0].

The same way, if I set my data in

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 22:13

    Yes, storing 0 and 1 as the key will have an issue as Firebase will think it is an array.

    My simple workaround is using:

    String(format:"%03d", intValue)
    

    So that the resulting key will be "000" and "001", and they can be converted back to Int with ease.

提交回复
热议问题