In this episode, we're focusing on adding the ability to delete notes from our notes app. Even though deleting might sound straightforward, we run into a few interesting edge cases! We first hook up our delete button to ask for confirmation before deleting. Then, we connect it to a method that removes the note from our data array.
Along the way, we notice some bugs—like what happens if the note we're viewing is the one we delete? It turns out, we need to handle resetting the current note selection so the app doesn't break. We also make sure to persist notes after deletion and select the next note in the stack.
Lastly, we handle the scenario where the user tries to delete the very last note: instead of leaving them with no notes, we automatically create a new blank note for them. By the end of the video, you'll have a smoothly working delete feature that 'just works,' even in those pesky edge cases!