【问题标题】:Retrieve nested data from firebase using Swift使用 Swift 从 firebase 检索嵌套数据
【发布时间】:2019-03-20 02:28:55
【问题描述】:

如何访问嵌套的网站 url。我也不知道如何访问 Medium 部分下的 img。我可以通过提供的图像中的代码访问其他信息没有问题:

What my firebase looks like

What my code looks like

    ref = Database.database().reference()

    ref.child("artists").queryOrderedByKey().observe(.value) { snapshot in
        var temp = [Artist]()
        for child in snapshot.children {

            if let child = child as? DataSnapshot {
                // decode json into Artist Struct
                let model = try! FirestoreDecoder().decode(Artist.self, from: child.value as! [String : Any])
                temp.append(model)

               // print(model)

            }
        }

【问题讨论】:

  • 问题中的代码实际上并没有访问 Firebase 中的任何内容——它是一个 Swift 结构。请包含您现有的 Firebase 代码,以便我们了解问题所在。查看How to create a Minimal, Complete, and Verifiable example
  • 很抱歉。我将更新我的帖子以包含解码 json 文件的代码

标签: ios swift firebase firebase-realtime-database


【解决方案1】:
Let ref = Database().database.refrence()

ref.child("TopNode").child("secondInerNode").observe(.value, with: {//stuff})

您将路径写入您拥有数据的位置,然后观察。

TopNode
   secondInerNode
      name: value;

Check the docs for more info.

【讨论】:

  • 感谢您的快速回复。我刚刚更新了我的帖子以表明这是我当前的代码。阅读文档后,我仍然不确定如何提取嵌套数据:2 img 和网站。感谢您的帮助
  • child.childSnapshot("name of what u want") justy do .somthing 并通过选项搜索您想要的内容
猜你喜欢
  • 2017-12-22
  • 1970-01-01
  • 2021-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多