我希望当用户已经按下反对票时,下次他们按下反对票按钮时,他们将从反对票字典中删除。
Firebase.getDownvote(selectedPostTimeStamp: postItem.timeStamp) { (error, downvoteFinalDictionary) in
let keyExists = downvoteFinalDictionary?[Current.user.userID!] != nil
// if the current user exists in the downvote dictionary
if keyExists {
print("Current UID exist")
// remove the current user from the downvote dictionary
self.databaseRef.child("channels").child(Current.user.channel).child("posts").child("post").child(Current.user.userID!).removeValue()
} else {
// uid doesn't exist
}
我也试过这个:(
self.databaseRef.child("channels").child(Current.user.channel).child("posts").child("post").child(Current.user.userID!).removeValue(completionBlock: { (error, databaseReference) in
print("\n\n\n DATA IS SUPPOSED TO BE GONE!!!!!")
})
最佳答案
看起来您的结构与您的 Firebase 查询不匹配。您的结构是 channel > channel > 帖子 > 帖子 > 日期 > 用户 ID。但是您尝试的代码是 channel > channel > 帖子 > 帖子 > userId。 Firebase 无法在该路径中找到 userId,因此不会发生任何事情。
试试下面的代码让你更接近:
self.databaseRef.child("channels")
.child(Current.user.channel)
.child("posts/post")
.observeSingleEvent(type: .value, with: { (snapshot) in
})
如有必要,我稍后会编辑此代码以帮助您进一步了解。我现在不在我的 Mac 旁边。
关于ios - 为什么在 Firebase removeValue() 中删除数据不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43193090/