Data Persistence & Publishing
Choosing how to store data
iOS offers several ways to save data, and picking the right one matters:
- UserDefaults — tiny key-value data like settings and flags.
- Files (Codable + FileManager) — documents or cached JSON.
- Core Data / SwiftData — large, structured, related data you query.
- Keychain — small secure data like tokens and passwords.
UserDefaults
UserDefaults.standard.set(true, forKey: "darkMode")
let dark = UserDefaults.standard.bool(forKey: "darkMode")
Use it only for small preferences — never for large data or secrets.
Saving Codable objects to a file
let url = FileManager.default
.urls(for: .documentDirectory, in: .userDomainMask)[0]
.appendingPathComponent("users.json")
// save
let data = try JSONEncoder().encode(users)
try data.write(to: url)
// load
let loaded = try JSONDecoder().decode([User].self, from: Data(contentsOf: url))
Core Data and SwiftData
Core Data is Apple’s mature framework for large, relational, persistent data (think a notes app with thousands of entries and relationships). It has a learning curve. For new apps on iOS 17+, SwiftData offers a much simpler, Swift-first API over the same engine — you mark a class @Model and it’s persisted.
Securing sensitive data with Keychain
Never store passwords or auth tokens in UserDefaults — it isn’t encrypted. Use the Keychain, the system’s secure, encrypted store, for anything sensitive.
Preparing to publish
- Join the Apple Developer Program (about $99/year).
- Set your app’s bundle identifier, version and build number.
- Add an app icon and launch screen.
- In Xcode: Product → Archive to build a release version.
- Upload it to App Store Connect from the Organizer window.
Submitting for review
In App Store Connect you create the store listing (name, description, screenshots, keywords, privacy details), attach your uploaded build, and submit for App Review. Apple reviews every app against its guidelines — this usually takes a day or two. Once approved, your app goes live. Updates follow the same archive-and-submit flow with a higher build number.
Common mistakes
- Storing tokens/passwords in UserDefaults instead of the Keychain.
- Missing privacy descriptions in Info.plist (App Review will reject).
- Forgetting to increase the build number for each upload.
Summary: Match storage to need — UserDefaults for settings, files for documents, Core Data/SwiftData for big data, Keychain for secrets. To publish, archive in Xcode, upload to App Store Connect, complete the listing, and submit for review.