How to get index path on click of button from UITableView in Swift 5

1) In your Custom cell add closure:

class YoutuberTableViewCell: UITableViewCell {

    var buttonAction : (() -> ())?


    @IBAction func buttonTapped(_ sender: UIButton) {

        buttonAction?()
    }

}

2) In your cellForRowAt implement the closure

extension ViewController : UITableViewDataSource {

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier, for: indexPath) as! YoutuberTableViewCell

        cell.buttonAction = { [unowned self] in
            let selectedIndexPath = indexPath.row
        }

        return cell
    }

}