【发布时间】:2021-07-30 12:37:32
【问题描述】:
我正在尝试从 Firestore 中检索 Int,但我不能说“调用 'append' 的结果未使用” 这是我的代码:
class pointsM: ObservableObject {
@Published var point = 0
init() {
let db = Firestore.firestore()
let user = Auth.auth().currentUser?.uid
db.collection("Male").document(user!).getDocument { (snap, error) in
if error != nil{
print("Error")
}else{
let points = snap!.get("Coins") as? Int ?? 0
self.$point.append(points)
}
}
}
}
【问题讨论】:
-
将
self.$point.append(points)更改为self.point.append(points) -
它给了我一个错误。 "引用实例方法 'append' 需要包装器 'Published
.Publisher'" -
对不起,我刚刚意识到 self.point 不是一个数组。只需这样做
self.point = snap?.get("Coins") as? Int ?? 0 -
追加函数调用让我失望
-
为什么要反复强制解包变量?
标签: swift google-cloud-firestore