简体   繁体   English

如何使用 Xcode 中的 Swift 访问 Firebase 中的 Cloud Firestore 数据库中的数据?

[英]How do I access the data from Cloud Firestore database in Firebase using Swift in Xcode?

I am new to Firebase and basically I want to access the elements in the documents that are the id fields in each of the documents and I want to loop through them, is there any way I can retrieve and put that data in some kind of array and later loop through the array in swift?我是 Firebase 的新手,基本上我想访问文档中的元素,这些元素是每个文档中的id字段,我想遍历它们,有什么方法可以检索并将该数据放入某种数组中然后循环遍历 swift 中的数组? I am new here in StackOverflow please don't mind if I didn't ask the question properly.我是 StackOverflow 的新手,如果我没有正确提出问题,请不要介意。 The link to the image how my database looks like is below please go through it.我的数据库看起来如何的图像链接如下,请 go 通过它。

So this is how my CloudFirestore Database looks like这就是我的 CloudFirestore 数据库的样子

For This you have to setup Firebase Client SDK https://github.com/firebase/firebase-ios-sdk and after successfully setup为此,您必须设置 Firebase 客户端 SDK https://github.com/firebase/firebase-ios-sdk并在成功设置后

let db = Firestore.firestore()
        db.collection("UniqueId's").getDocuments { (snapshot, error) in
            if error != nil {
                print(error)
            } else {
                for document in (snapshot?.documents)! {
                    if let id = document.data()["id"] as? String {
                    //Here you'll get your data
                }
            }

By the way I think your collection name may be a problem So if it is than change it's name to UniqueIds instead of UniqueIds顺便说一句,我认为您的收藏名称可能是一个问题所以如果不是将其名称更改为 UniqueIds 而不是 UniqueIds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Swift 中的 Cloud FireStore Firebase 访问特定字段 - How to access a specific field from Cloud FireStore Firebase in Swift 如何使用 swift 在 Firebase Cloud Firestore 中获取文档的 position? - How do I get the position of a document in Firebase Cloud Firestore using swift? 使用 Swift 更新 Cloud Firestore 数据库中的数据 - Update data in Cloud Firestore database using Swift 如何从Firebase Cloud Firestore提取数据 - How to extract data from Firebase Cloud Firestore 如何使用Firebase数据库通过Xcode / Swift在表视图中显示多个路由/子级 - How do I use Firebase Database to display multiple routes/childs in Table View using Xcode/Swift 如何使用iOS和Swift语言从Firebase数据库将字符串类型数据转换为整数类型数据 - How do I convert string type data to integer type data from firebase database in ios & swift language 如何将 Firestore 数据存储在可以在 Swift/Xcode 中操作的变量中? - How do I store Firestore data in a variable that I can manipulate in Swift/Xcode? 如何使用Swift从Xcode中的代码访问预处理器宏? - How do I access a preprocessor macro from code in Xcode using Swift? Swift,iOS:如何从Firebase数据库提取数据? - Swift, iOS: How do I extract data from my firebase database? Swift&Firebase-云Firestore可扩展吗? - Swift & Firebase - Cloud firestore scalable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM