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.
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!
We are removing the appropriate note from the notes array, using the row property of the passed in indexPath.
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:
Implemented tableView(_:commitEditingStyle:forRowAtIndexPath:) in the ListNotesTableViewController so that users can delete notes by swiping right on them.
We have placed cookies on your device to ensure that we give you the
best experience on our website.
acknowledge that you have read and understand our
Terms of Service. Your use of
Make School’s Products and Services is subject to these policies and terms.