[英]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.