gpt4 book ai didi

ios - Swift 3 中的 Firebase 多级数据库处理

转载 作者:行者123 更新时间:2023-11-28 15:34:19 26 4
gpt4 key购买 nike

我知道如何将单级数据插入到 firebase 数据库中。但我想插入值并从具有多级结构的 firebase 数据库中获取值。

我在 [String: [String: [String]]] 的结构中有字典,我想将这个值插入表 my-test-table 使用我自己的 key 作为 my-sample-key。然后我想使用具有相同字典格式的 my-sample-key 获取数据。

在 firebase 数据库中可以吗?

谢谢。

最佳答案

好消息:它有效

//Save Data
let myDictionary = [String: [String: [String]]]()

let ref = FIRDatabase.database().reference().child("allOfMyDictionarys").child("my-sample-key")
ref.setValue(myDictionary)

// Recive data
ref.observe(FIRDataEventType.value) { (snap: FIRDataSnapshot) in
if let data = snap.value as? [String: [String: [String]]]{
//Do something here
}
}

因为 Firebase 使用类似 JSON 的数据结构,所以您不再有表格之类的东西。所以你不需要你的“我的测试表”,因为只有一个文件。为了构建数据,我添加了“allOfMyDictionarys”子项。 JSON 格式的另一个优点是您可以毫无问题地保存 Array 的字典。

关于ios - Swift 3 中的 Firebase 多级数据库处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44442351/

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