我对 Firebase 的新 Cloud Firestore 相对较新,并且在尝试将数据映射到/从时遇到困难。我已经尝试通过 Google 在线查看文档,但它有一些我无法弄清楚的问题。
[String : Any]
自定义结构转换时,文档建议我尝试以下操作:docRef.getDocument { (document, error) in
let result = Result {
try document.flatMap {
try $0.data(as: City.self)
}
}
switch result {
case .success(let city):
if let city = city {
print("City: \(city)")
} else {
print("Document does not exist")
}
case .failure(let error):
print("Error decoding city: \(error)")
}
}
Run Code Online (Sandbox Code Playgroud)
然而,这产生就行错误$0.data(as: City.self)
与类型的值“NSObject的”没有成员“数据”。
do {
try db.collection("cities").document("LA").setData(from: city)
} catch let error {
print("Error …
Run Code Online (Sandbox Code Playgroud)