DEV Community

Maegan Wilson
Maegan Wilson

Posted on

Day 008: Making a TODO list

GitHub Repo

Question: Where are days 6 and 7?

Answer: I didn't do any coding since it was the
weekend, and I was busy.

Things I want to accomplish

  • Slide to delete

Things I accomplished

  • Slide to delete

Things I learned

The function needed to add "Slide to delete".

The function needed is this one

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        // CODE GOES HERE
    }

The way I chose to implement the function is checking if the
editingStyle is equal to .delete and inside that check, I do the following:

  • Delete the todo
  • Delete the row from the table view

Here is the final code

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            todos.deleteTodo(index: indexPath.row)
        }
        tableView.deleteRows(at: [indexPath], with: .left)
    }

If you have any questions about what I did or how I implemented anything, let me know! If you have any suggestions or other comments, let me know as well!

Top comments (0)