【发布时间】:2017-12-05 22:57:53
【问题描述】:
我只是希望得到一个解释:下面发生了什么。 在第一个 if let 语句中,其中 document = document flatmap 不再是 DocumentSnapshot 的成员,而在第二个 if let 中,我显然能够在 if let 语句中调用文档上的 flatmap。我只是不太明白为什么会这样。
我检查了类型,它们都是 DocumentSnapshots,唯一的区别是一个是可选的。
谢谢。
var docref:DocumentReference?
docref = db.collection("users").document(uid)
docref?.getDocument { (document, error) in
if let document = document{
//document.flatmap won't work
//value of DocumentSnapshot has no member flatmap
}
if let profile = document.flatMap({$0.data()})
{
self.model.currentLoggedInUser?.id = profile["id"] as! String
}
【问题讨论】:
标签: swift google-cloud-firestore