Q:

Want to remove a row from the tableview and delete the corresponding object from the array

I want to delete one row from a tableview in Swift 5 and remove the object from the array. I searched a lot but couldn't get it done.
I tried all the related solutions available on StackOverflow but couldn't find it.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
    let position = indexPath.row
    if (editingStyle == .delete) {

        labDetailsTableView.beginUpdates()
        if let idx = labs.firstIndex(where: { $0 === position }) {
            labs.remove(at: idx)
        }

        labDetailsTableView.endUpdates()
    }
}

Binary operator '===' cannot be applied to operands of type 'LabDetails' and 'Int'

A:

Replace the if let block with just labs.remove(at: position). No need for firstIndex.
You also do not need the calls to beginUpdates or endUpdates. But you do need to add a call to tableView.deleteRows(at: [indexPath], with: .fade).
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
    if (editingStyle == .delete) {
        let position = indexPath.row
        labs.remove(at: position)
        tableView.deleteRows(at: [indexPath], with: .fade)
    }
}

