DEV Community

Maegan Wilson
Maegan Wilson

Posted on

2

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!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay