SwiftData

SwiftData is Apple's Swift native persistence framework, introduced in 2023 as a modern layer over the same storage engine Core Data uses. You declare models with the Model macro instead of a visual schema editor, and SwiftUI views stay in sync automatically.
Why it exists
Core Data has powered iOS persistence for over a decade, but it predates Swift and it shows: NSManagedObject subclasses, a separate visual schema editor, and NSFetchRequest APIs feel bolted onto a language with strong typing and macros. SwiftData exists to give developers Core Data's proven storage engine, including migrations and iCloud sync, through an API that looks and feels like ordinary Swift code.
The mental model
Think of SwiftData as Core Data wearing a Swift shaped costume. Underneath, the same battle tested SQLite backed engine does the storing, migrating, and syncing. What changes is the surface: a schema is just a class with an @Model attribute instead of a separate file, and queries are Swift property wrappers instead of a fetch request builder.
How it works
You mark a class with the @Model macro, which generates conformance to PersistentModel and rewrites stored properties to route through SwiftData's storage layer at compile time. A ModelContainer is created for a schema, usually once at app launch, and holds the actual store. A ModelContext, injected into SwiftUI's environment, tracks inserts, updates, and deletes, saving them either automatically or with an explicit call. Inside a view, the @Query property wrapper runs a fetch descriptor and keeps its results live, so the view redraws when matching data changes, mirroring how an observable object drives updates elsewhere in SwiftUI.
When it matters
It matters when choosing how a new app persists structured data locally. SwiftData is the simpler choice for straightforward models and standard SwiftUI apps, cutting significant boilerplate versus Core Data. The footgun is assuming full feature parity: complex Core Data setups, like custom migrations with heavy data transformation logic or several configurations sharing one store, still sometimes need Core Data directly, and SwiftData's minimum deployment target of iOS 17 rules it out for apps supporting older devices.
A concrete example
A recipe app defines an @Model class Recipe with a title, an ingredients array, and a relationship to a Category model. In a SwiftUI list view, @Query private var recipes: [Recipe] fetches and observes all recipes with no manual fetch request, and calling modelContext.insert on a new recipe immediately updates the list on screen.
Interview question
What does the @Model macro actually do when applied to a Swift class in SwiftData?
- a.It converts the class into a JSON codable struct for network transport
- b.It generates persistence machinery at compile time, conforming the class to PersistentModel and routing its properties through SwiftData's storageCorrect
- c.It creates a visual schema file similar to Core Data's xcdatamodeld editor
- d.It marks the class as thread safe so it can be shared across actors without a ModelContext
Why? this is the answer
The @Model macro is a compile time Swift macro that wires stored properties into SwiftData's persistence layer and conforms the type to PersistentModel, replacing the xcdatamodeld editor entirely rather than generating one. It does not by itself make the type safe to share across concurrency contexts.
Just read this? Test yourself on what you have been reading.
Read the original → developer.apple.com
- #swiftdata
- #ios
- #error
- #source-issue
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles