Day 008: Making a TODO list

Jay Wilson
1 min readFeb 5, 2019

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!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Jay Wilson
Jay Wilson

Written by Jay Wilson

I like to solve problems using Swift, make YouTube videos, and take photos. I also really enjoy a good cup of coffee.

No responses yet

Write a response