Q:

Remove objects from array when deselect table view

I have a table view which show a list of things with id, name, price & quantity (got from itemsArr array). When I select one of the item, I will append the details of the thing (id, name, price, quantity) into an array (items array). And when I deselect the item, the details (id, name, price, quantity) of the item which has been appended into that array should be removed. I have no issues to append the details into an array, but my problem is I don't know what is the best way to remove all the details of that item from the array. Below is my code:
var item = MyList()
var items = [MyList]()
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath)
        cell?.accessoryType = .checkmark

        if let itemSel = itemsArr?[indexPath.row] {
            delegate?.didSelectItemsListItem(id: itemSel.id, name: itemSel.name, price: itemSel.price)
            // Add item details into array
            item.id = itemSel.id
            item.name = itemSel.name
            item.price = itemSel.price
            item.quantity = 1
            self.items.append(item)
            print("Added items: ", self.items)
        }
    }

    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath)
        cell?.accessoryType = .none
        // Remove item details from array
        if let itemdeSel = itemsArr?[indexPath.row] {
            delegate?.didDeselectItemsListItem(id: itemdeSel.id, name: itemdeSel.name, price: itemdeSel.price)
            if let index = itemsArr?.index(where: { $0.id == itemdeSel.id }) {
                // removing item
                self.items.remove(at: index)
                print("Items after removed: ", self.items)
            }
        }
    }

noted that the quantity for all items is 1. I want to try using filter method but I'm afraid that all quantity of other items will also be removed since the quantity is the same. Below is the example of items array (which the items has been appended into it:
 [(id: 4, name: "book", price: "3.00", quantity: 1), (id: 2, name: "pen", price: "1.00", quantity: 1)]

UPDATE:
I can actually just use the filter method. I didn't know filter method can remove the whole details of that item. Below is my final deSelect code:
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    let cell = tableView.cellForRow(at: indexPath)
    cell?.accessoryType = .none
    // Remove item details from array
    if let itemdeSel = itemsArr?[indexPath.row] {
        delegate?.didDeselectItemsListItem(id: itemdeSel.id, name: itemdeSel.name, price: itemdeSel.price)
        let filteredArray = self.items.filter { $0.id != itemdeSel.id }
        self.items.removeAll()
        self.items = filteredArray
        print("Items after removed: ", self.items)
    }
}

A:

If you have an array, itemsArr, and you know the id of the item that you want to remove, you can simple use, 
let filteredArray = itemsArr.filter { $0.id != idToDelete }

