我知道如何从 Firestore 获取多个文档,但正在努力弄清楚如何为单个文档执行此操作。我想使用从 Firestore 用户文档中提取的数据创建一个 User 实例。
func fetchUser (_ user_UUID: String) {
let docRef = db.collection("users").document(user_UUID)
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let dataSnatch = document.data().map(String.init(describing: )) ?? "nil"
let user1 = try! User(from: dataSnatch as! Decoder) //THIS DOESN'T WORK
} else {
print("Document does not exist")
}
}
}