I am trying to delete a row in a tableview that I am presenting using an array of objects. I have added a remove button at the corner and on the click it should remove the selected row but instead it always removes the first row no matter which row I click at.
I declared a variable first: private var indexForCell = Int()
then I am using tableview method didSelectRowAt like this:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        indexForCell = indexPath.row
    }
Then I use my button that I added for deletion:
    @IBAction func removePokemon(_ sender: UIButton) {
        favourites.remove(at: indexForCell)
        self.tableView.reloadData()
    }
This makes the row delete but always the first one. Whichever row I select, it removes the first row always. How can I stop this?