无法从 Firebase 检索 Int



我试图从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)
}
}
}

}

您的问题是类型冲突,以及危险的强制展开。

class PointsM: ObservableObject {
@Published var point = 0
init() {
if let user = Auth.auth().currentUser?.uid {
Firestore.firestore().collection("Male").document(user).getDocument { (snap, error) in
if let doc = snap,
let point = doc.get("Coins") as? Int {
self.point = point
} else if let error = error {
print(error)
}
}
}
}
}

相关内容

  • 没有找到相关文章

最新更新