[英]Firestore Swift: Get number of nested maps stored in a document
I have a document with fields structured something like this:我有一个文档,其字段结构如下:
Is there any way to count the number of nested maps?有没有办法计算嵌套地图的数量? So in this case, I want to show that I have two "elements",
JGBQBnFX23Mh5NL4W8f3N1E5Czu1
and JGBQBnFX23Mh5NL4W8f3N1E5Czu1
所以在这种情况下,我想表明我有两个“元素”,
JGBQBnFX23Mh5NL4W8f3N1E5Czu1
和JGBQBnFX23Mh5NL4W8f3N1E5Czu1
Right now, I only know how to retrieve everything under "attendees" using现在,我只知道如何使用“参加者”检索所有内容
db.collection("Collection")
.document(eventID)
.getDocument { doc, err in
if let err = err {
print(err.localizedDescription)
return
}
let data = doc?.data()
let attendees = data?["attendees"]
print(attendees)
}
But I do not know how to get the total count (of my document IDs)但我不知道如何获得(我的文档 ID)的总数
Keep in mind I will not be able to use arrays in my scenario.请记住,我将无法在我的场景中使用 arrays。 Thanks!
谢谢!
It turns out it could be fixed by changing事实证明它可以通过改变来修复
let attendees = data?["attendees"]
to至
let attendees = data?["attendees"] as? Dictionary<String, Any>
and then you could get the total count by doing attendees?.count
然后你可以通过做
attendees?.count
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.