Now that we can add new notes and modify existing notes, let's make it so users can delete notes.

We would like our users to be able to swipe right on a note and be presented with a delete option:

Luckily, table views make this incredibly easy.

Add the following method to the ListNotesTableViewController class:

// 1
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    // 2
    if editingStyle == .Delete {
        // 3
        // 4
  1. By implementing tableView(_:commitEditingStyle:forRowAtIndexPath:), we enable the the table view to have additional editing modes, one of which is that the cells display the delete option when a user swipes right. The other mode is an insert mode, but that won't appear without additional configuration.

  2. We check to see if the editingStyle is the .Delete one - there's also an .Insert one. We wouldn't want to accidentally delete a user's notes when they intended to insert a new one!

  3. We are removing the appropriate note from the notes array, using the row property of the passed in indexPath.

  4. Because we modified the notes array, we must tell the table view to update itself with reloadData().

And that's all we have to do to delete a note! =]

Running the App!

You should now be able to add, modify, and delete notes!

In the next tutorial we will start working on persisting data between app launches!

On this page, you should have:

  1. Implemented tableView(_:commitEditingStyle:forRowAtIndexPath:) in the ListNotesTableViewController so that users can delete notes by swiping right on them.
  2. Run and tested your app!


If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations in San Francisco and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more

Cookies on Make School's website

We have placed cookies on your device to ensure that we give you the best experience on our website.

This site uses cookies to deliver our services. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Your use of Make School’s Products and Services is subject to these policies and terms.

Please note that Make School no longer supports Internet Explorer

We recommend upgrading to a modern web browser. Learn more