【发布时间】:2017-11-27 09:18:44
【问题描述】:
我开始使用 Firestore 并偶然发现了一个问题。
Firestore 文档中用于检索文档的代码是:
let docRef = db.collection("cities").document("SF")
docRef.getDocument { (document, error) in
if let document = document {
print("Document data: \(document.data())")
} else {
print("Document does not exist")
}
}
但是,如果我没有具有该id的文档,“让文档=文档”将始终通过,它会尝试打印不存在的文档数据,从而导致错误。
现在,这很容易通过将 if 更改为:
if let document = document, document.exists {
...
}
这不也应该记录在案吗?还是我忽略了什么?
编辑:Link to docs
【问题讨论】:
标签: swift firebase google-cloud-firestore