从基于 Firebase 的云数据库中获取用户数据并转换为字典 [英] Get the user data from firebase cloud-based database and convert into dictionary

查看:42
本文介绍了从基于 Firebase 的云数据库中获取用户数据并转换为字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 swift 的新手,我正在尝试从 firebase cloudbase 数据库中获取数据并尝试在字典中分配它们.

I am new to swift and I am trying to get the data from the firebase cloudbase database and trying to assign them in dictionary.

我尝试将它们放在字典中并打印值,但它没有显示任何错误消息或在控制台上打印任何内容.

I have tried putting them on a dictionary and printing the values but it doesnot show anyerror message or print anything on the console.

func fetchUser(){
        let db = Firestore.firestore()
        db.collection("users").getDocuments() { (querySnapshot, err) in
            if let err = err {
                print("Error getting documents: \(err)")
            } else {
               for document in querySnapshot!.documents {
                if let dict = document as? Dictionary<String, Any> {
                    let email = dict["email"] as! String
                    print(email)
                }
               }
             }
         }
    }

我想打印用户集合中的所有电子邮件并显示在控制台上.

I want to print all the email from the users collection and display on the console.

推荐答案

希望对你有帮助

for document in querySnapshot!.documents {
    let documentValue = document.data() // default dictionary
    print(documentValue["email"] as! String)
}

这篇关于从基于 Firebase 的云数据库中获取用户数据并转换为字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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