project quicknotes

Step 4: Persistence

System Text-to-Speech Ready
Slide: 0:00 / 0:00
Slide 1 of 0Interactive Deck

Full Lesson Reference

Save notes automatically.

Where We Are

Notes work but vanish when you quit the app. Let's save them.

Auto-Save

terminal
Save notes automatically:
- Save whenever the text changes (with a small debounce delay)
- Save when the popover closes
- Save when the app quits
- Load saved notes when the app starts

Use UserDefaults or a JSON file in Application Support.

Test It

  1. Open QuickNotes, type something
  2. Quit the app completely (right-click menu bar icon → Quit, or Cmd+Q)
  3. Re-launch from Xcode
  4. Your notes should still be there

Remember the Last Note

terminal
When the app reopens, show the last note the user was editing.
Save the selected note index along with the notes.

Checkpoint

By now you should have:

  • Notes save automatically
  • Data survives app restarts
  • Last-viewed note is restored
  • No manual save button needed

What You Learned

  • Persistence with UserDefaults or JSON files
  • Auto-save patterns
  • App lifecycle events (quit, launch)
  • Restoring user state

Exercises

  1. Run the "Auto-Save" prompt, type a note, quit with Cmd+Q, and relaunch to confirm your notes persist.
  2. Apply the "Remember the Last Note" prompt, switch to a second note, quit, and verify that same note is selected on relaunch.
  3. Find where your notes are stored (UserDefaults or the JSON file in Application Support) and inspect the saved data to understand the format.