Save information on the phone
An app should remember useful information after you close it.
Keep records between launches without adding an online service.
Let’s do this
- 1In Codex
Decide what should be remembered
List the information your app needs to keep, such as an item’s name, notes and completed status. Do not save information simply because you might want it someday.
- 2In Codex
Use the phone’s own storage first
Ask Codex to use suitable built-in Apple storage. SwiftData is Apple’s tool for saving structured records; small preferences may use a simpler store. Tell Codex not to add iCloud or a database subscription in this lesson.
- 3In Xcode
Test a full close and reopen
Create an item, change it, then stop the app in Xcode and run it again on the same simulator. Confirm the change is still there. Test deleting a record too.
- 4In Codex
Understand what this does not protect against
Local storage belongs to this installation. Deleting the app may remove its records, and a different simulator is a different device. If the information will matter, plan an export, backup or syncing route before people depend on it.
View largerA message for Codex
Make my first iPhone app remember the records needed for [describe the problem my app should solve] between launches. Use appropriate built-in Apple storage, such as SwiftData for structured records, and explain the choice. Keep the data on this device for now. Preserve existing records when changing the app. Add a meaningful persistence check and give me steps to test create, edit, delete, close and reopen. Explain what happens if the app is deleted.
What you should see
An item and its changes are still present after a full stop and restart on the same device. Deleted items stay deleted.
A couple of words, explained
- Local storage
- Information kept on this device rather than in an online service.
- Database
- An organised store of information the app can save and look up.
If you get stuck
Checked 7 September 2026. Screens can change; the official guides below have the latest steps.
Saving data between launches