13.4 · SwiftData: models, contexts, predicates, actors and schema evolution
SwiftData is Core Data’s modern face: the same ideas (a context of objects, a store, migrations) with Swift macros and a SwiftUI-first API.
Mental model. You still have a container, a context per queue and a schema that must evolve. The macros remove the boilerplate, not the rules.
Using SwiftData
Models, the context, predicates and fetching.
- How do SwiftData’s @Model, ModelContainer, ModelContext, #Predicate and FetchDescriptor work together?
A class marked @Model becomes persistent: the macro rewrites its stored properties so changes are tracked and observable (it also makes the class Observable…
Threads and versions
Model actors and versioned schemas.
- How do ModelActor, context-per-actor and VersionedSchema work in SwiftData, and what can you pass between actors?
As with Core Data, a ModelContext is not Sendable and models are bound to their context, so the rule is one context per isolation domain. SwiftData supports…
More in Persistence & data
- 13.1 · Where data belongs, and the Keychain
- 13.2 · SQLite fundamentals: transactions, WAL, constraints, indexes and migrations
- 13.3 · The Core Data stack, contexts and faults, concurrency, and migrations
- 13.5 · The repository pattern and cache design
- 13.6 · Crashes mid-write, integrity, backups and data protection
- 13.7 · Syncing data across devices: conflicts, tombstones and CloudKit
- 13.8 · UserDefaults surprises and FileManager essentials
- 13.9 · Reading query plans, typing and NULL, WAL locking, savepoints and full-text search
- 13.10 · Merge conflicts, faults and batch requests, delete rules, and the SwiftData context
- 13.11 · Keychain status codes, detecting corruption, an LRU cache and library trade-offs