1 min read
Step 4: Persistence
Save notes automatically.
Where We Are
Notes work but vanish when you quit the app. Let’s save them.
Auto-Save
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
- Open QuickNotes, type something
- Quit the app completely (right-click menu bar icon → Quit, or Cmd+Q)
- Re-launch from Xcode
- Your notes should still be there
Remember the Last Note
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