[英]Delete Post from Firebase Database
Post Structure retrieving the data 发布结构以 检索数据
I'm trying to delete posts from the Firebase Database. 我正在尝试从Firebase数据库中删除帖子。 I'm having a ruff time removing values that are generated from an AutoID.
我正在腾空时间删除从AutoID生成的值。
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete{
let user = FIRAuth.auth()?.currentUser
let uid = user?.uid
ref?.child("tests").child(uid!)/* The Posts AutoID*/.removeValue()
tableView.reloadData()
}
}
You'll need to retrieve the post IDs when the data is being fetched. 提取数据时,您需要检索帖子ID。 For example, when fetching data just grab the post ID as well.
例如,在获取数据时,也只需获取帖子ID。
ref.child("tests").child(uid!).observeSingleEvent(of: .value, with: { snapshot in
for child in snapshot.children {
let childSnap = child as! FIRDataSnapshot
print(childSnap.key) // SAVE THIS KEY SOMEWHERE, USE IT TO DELETE
}
)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.