Deleting Rows

In editing mode, the red circles with the minus sign (shown in Figure 11.7) are deletion controls, and tapping one should delete that row. However, at this point, you cannot actually delete the row. (Try it and see.) Before the table view will delete a row, it calls a method on its data source about the proposed deletion and waits for confirmation.

When deleting a cell, you must do two things: remove the row from the UITableView and remove the Item associated with it from the ItemStore. To pull this off, the ItemStore must know how to remove objects from itself.

In ItemStore.swift, implement a new method to remove a specific item.

func removeItem(_ item: Item) {
    if let index = allItems.index(of: item) {
        allItems.remove(at: ...

Get iOS Programming: The Big Nerd Ranch Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.