【问题标题】:Get the user data from firebase cloud-based database and convert into dictionary从 firebase 基于云的数据库中获取用户数据并转换为字典
【发布时间】:2019-12-26 09:39:41
【问题描述】:

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

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

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)
                }
               }
             }
         }
    }

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

【问题讨论】:

    标签: ios swift swift3 swift2 xcode8


    【解决方案1】:

    希望对你有帮助

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 2019-07-13
      相关资源
      最近更新 更多