First of all, I didn't see any question related to this. I am trying to delete specific value from Firebase which value is got from tableview cell
.
First I enable
delete button if post == username
like this inside cellForRowAt indexPath: IndexPath
function:
if postsArray[indexPath.row].username == currentUser.generalDetails.userName{
cell.deletePostButton.isHidden = false
}else{
cell.deletePostButton.isHidden = true
}
And here I call deletePost() function:
cell.deletePostButton.addTarget(self, action: #selector(deletePost), for: .touchUpInside)
And I try to run this function but it terminates the app:
func deletePost(sender: UIButton, cellForRowAt indexPath: IndexPath){
FIRDatabase.database().reference().child("posts").child(postsArray[indexPath.row].postId).removeValue()
}
To illustrate this, that is my tableview with the delete button and the delete button(inside red thing) should delete the row from Firebase:
Why the function terminates the app?