swiftdata
SwiftData
Apple's modern persistence layer (the Core Data successor) — @Model classes, a ModelContainer, ModelContext for CRUD, and @Query for reactive SwiftUI fetches. The deep API reference — model attributes, relationships, fetching, migrations, concurrency, CloudKit, iOS 26 additions — lives in references/guide.md. This file is the decision and discipline layer: read it first, open the guide for specifics.
Dials
Set these explicitly at the start; they change what "correct" means.
CONCURRENCY—main-context(default; all reads/writes onmainContextfrom@MainActorcode) ·model-actor(heavy imports, batch writes, or background work go through a@ModelActor-isolated context —ModelContextis notSendableand may not cross actors).MIGRATION—lightweight(additive changes pre-ship, or trivial property adds with defaults) ·versioned-schema(anything shipped to users:VersionedSchema+SchemaMigrationPlan, lightweight or custom stages).CLOUDKIT_SYNC—off(default; local store only) ·on(.modelContainer(... ,cloudKitDatabase:)orModelConfiguration(cloudKitDatabase: .automatic)— forces extra schema constraints, see anti-rationalization).
When to use
Designing or reviewing any local data model, query, write path, relationship graph, schema migration, or CloudKit-synced store that goes through SwiftData. iOS 17+ for the framework, iOS 18+ for #Index/#Unique, iOS 26 the default target. If the app is on Core Data and not migrating, this skill does not apply; if it's migrating off Core Data, it does.