swift - 从 autoID 节点中检索值

标签 swift firebase

我想从 autoID 节点中获取值。以下是我的结构:

"workout"
  "exercise"
    "Bench Press"
      "(AutoIDNode)"
        "reps: 10"
        "set: 1"
        "weight: 60"

如何获取“次数”、“组数”和“重量”的值。

这是我的快速代码:

refSets.child("workout").child("exercise").child("Bench Press").observe(DataEventType.value, with: {(snapshot) in
        if snapshot.childrenCount > 0 {
            self.setsData.removeAll()

            for sets in snapshot.children {
                let snap = sets as! DataSnapshot
                let key = snap.key
                let value = snap.value
                print(key)
                print(value!)
            }     
        }
    })

我知道我缺少 .child("Bench Press") 之后的 autoID 节点的 .child() 路径。我怎样才能访问这个节点?

提前致谢

最佳答案

你可以试试

refSets.child("workout").child("exercise").child("Bench Press").observeSingleEvent(of: .value, with: {(snapshot) in

    if let res = snapshot.value as? [String:[String:Int]] {

        for item in Array(res.values) {

            print(item["reps"])
        }

    }

})

关于swift - 从 autoID 节点中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55814594/

相关文章:

ios - AWS SNS 无法使用 createPlatformEndpoint

android - 如何解决 Firebase API 初始化失败(Android + Firebase)

javascript - 如何在webAPP中的firebase中添加新条目

android - 无法启动接收器 com.google.firebase.iid.FirebaseInstanceIdInternalReceiver

iOS 到 Node.js 后端 SSL 握手失败

Objective-C 代码的 Swift 3 闭包语法

ios - JSONDecoder 找不到存在的 key

swift - 删除运行时发现的标有 "rt"的测试

javascript - 在用户注销后从 Cloud Firestore 中清除用户数据

java - Firebase 检索父项和子项的数据并将其分配给类