【问题标题】:Firebase Multi Level database handeling in Swift 3Swift 3 中的 Firebase 多级数据库处理
【发布时间】:2017-06-08 17:42:18
【问题描述】:

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

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

在 firebase 数据库中可以吗?

谢谢。

【问题讨论】:

    标签: ios swift firebase firebase-realtime-database


    【解决方案1】:

    好消息:它有效

    //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 之类的数据结构,所以您不再拥有类似表格的东西。所以你不需要你的'my-test-table',因为只有一个文件。为了构造数据,我添加了“allOfMyDictionarys”子项。 JSON 格式的另一个优点是您可以毫无问题地保存 Array 的字典。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-04
      • 2018-04-18
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多