gpt4 book ai didi

ios - Firebase 查询 - 我得到某种类型的 NSArray 作为结果(只是有时)

转载 作者:可可西里 更新时间:2023-11-01 01:32:16 25 4
gpt4 key购买 nike

所以我有一个这样的 firebase 数据库:

userIndexes
-- 1: uid1
-- 2: uid2
-- 3: uid3

我想通过 key 获取uid。所以我会这样查询:

DataService.sharedInstance.DB_REF_USERS_INDEXED_BY_ID.queryOrderedByKey().queryStarting(atValue: "2").queryLimited(toFirst: 1).observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot.value)
})

当我使用 2 时或 3作为起点,我得到了这个打印品(这里是 2 ):

Optional({ 2 = uid2; })

我可以轻松地将其转换为 Dictionary<String, AnyObject>

但是当我使用 1作为起点,我明白了:

optional(<__NSArrayM 0x6000000494b0>( < null >, uid1 ) ) If I try to cast this to a Dictionary, it just gets nil

这是为什么?

最佳答案

我在 forum 中问过同样的问题..

You should avoid arrays (specifically, numeric, sequential ids) in distributed systems.

有关 Firebase 中如何处理类似数组的行为以及为什么应避免使用数组的更多信息:

它在旧的 firebase 文档中明确定义了在 firebase 中使用数组时发生的情况。检查Arrays in firebase Database

你也可以通过Best Practices: Arrays in Firebase .. 上面写着

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 will render it as an array.

关于ios - Firebase 查询 - 我得到某种类型的 NSArray 作为结果(只是有时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39122499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com