如何在Swift的Firebase中的嵌套键中获取值 [英] How to get values inside nested keys in Firebase on Swift

查看:47
本文介绍了如何在Swift的Firebase中的嵌套键中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Firebase中的两个嵌套键中获取值.

I'm trying to get values inside two nested keys in Firebase.

:

我需要将name的所有值放入数组中.这是我仅访问节点用户"的代码.我当时以为我可以一个接一个地使用"queryOrderedByKey",但是在那种情况下,xCode崩溃了,并说不允许多次查询.

I need to put all the value of name inside an array. Here is my code where I'm accessing just the node "user". I was thinking that I could use "queryOrderedByKey" one after another, but in that case xCode crashes and says something like multiple quires aren't allowed.

        Database.database().reference().child("user").queryOrderedByKey().observe(.childAdded) { (snapshot) in

        if snapshot.value != nil {

            let result = snapshot.value as! [String : AnyObject]

            if let name = result["name"] as? String {
                self.myArray.append(name)
            }

            DispatchQueue.main.async(execute: {
                self.tableView.reloadData()
            })

        }
    }

这就是打印结果时得到的.

And this is what I'm getting when printing the result.

推荐答案

这是答案

        Database.database().reference().child("user").observe(.childAdded) { (snapshot) in

        if let dictinoary = snapshot.value as? [String: Any] {
            if let myFinalStep = dictinoary["GeneralInformation"] as? [String: Any] {
                print(myFinalStep["name"])

            }
        }
    }

这篇关于如何在Swift的Firebase中的嵌套键中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆