【发布时间】:2019-10-11 06:30:36
【问题描述】:
我正在尝试从 1 个文档中将所有字段作为字典抓取。但是当我尝试这样做时,我只会返回空数组。我尝试从文档中获取帮助,但它不起作用。
这行代码显示它不是空的
print("缓存的文档数据:(dataDescription)")
var user:String = (Auth.auth().currentUser?.email)! // I used email as name of document.
var Groups = [String:Any]()
let docRef = AppDelegate.db.collection("JoinedGroups").document(user)
docRef.getDocument(source: .cache) { (document, error) in
if let document = document {
let dataDescription = document.data()
self.Groups = dataDescription! // unwrapping here
print("Cached document data: \(dataDescription)")
} else {
print("Document does not exist in cache")
}
}
// Do any additional setup after loading the view.
print(Groups)
}
这是我的结果: 当我将鼠标悬停在定义上时,document.data() 显示为字典
[:] //显示为空??
缓存文档数据:可选(["test new": test new, "g3": g3, "g1": g1])
如果我能在这个问题上得到一些帮助,非常感谢。
【问题讨论】:
-
仅供参考,您可以使用编辑链接编辑您的问题,而不是在评论中添加新信息。
标签: swift firebase google-cloud-firestore