If you're building SwiftData persistence into a Swift or SwiftUI app, this skill walks you through the full stack: schema design with @Model and @Relationship, querying with FetchDescriptor, migrations with SchemaMigrationPlan, CloudKit sync setup, and ModelActor concurrency isolation. It starts by asking about your deployment target and container wiring before diving into solutions, which saves you from debugging phantom issues. The triage playbook is genuinely helpful, mapping common problems like empty fetches or duplicate rows to concrete next steps. It also flags anti-patterns like shipping schema changes without migration rehearsal. Solid if you're past the basics and need architectural guidance or migration safety checks.
npx -y skills add vanab/swiftdata-agent-skill --skill swiftdata-expert-skill --agent claude-codeInstalls into .claude/skills of the current project.
Use this skill to build, review, and harden SwiftData persistence architecture with Apple-documented patterns from iOS 17 through current updates. Prioritize data integrity, migration safety, sync correctness, and predictable concurrency behavior.
#Index, #Unique, HistoryDescriptor, DataStore, inheritance examples).ModelContainer wiring before debugging data issues; without it, inserts fail and fetches are empty.SchemaMigrationPlan when needed.rg "modelContainer\\(|ModelContainer\\(" -nrg "^@Model|#Unique|#Index|@Relationship|@Attribute|@Transient" -nrg "modelContext|mainContext|ModelContext\\(" -nrg "SchemaMigrationPlan|VersionedSchema|MigrationStage|fetchHistory|deleteHistory|historyToken" -nrg "cloudKitDatabase|iCloud|CloudKit|groupContainer|AppGroup|NSPersistentCloudKitContainer" -n.modelContainer(...) modifier or manual ModelContainer(...).save() is required.isUndoEnabled) and whether operations occur on mainContext or custom contexts.automatic, .private(...), .none).references/modeling-and-schema.md.references/model-context-and-lifecycle.md.references/querying-and-fetching.md.references/relationships-and-inheritance.md.references/migrations-and-history.md.references/cloudkit-sync.md.references/core-data-adoption.md.references/concurrency-and-actors.md.references/troubleshooting-and-updates.md.references/implementation-playbooks.md..modelContainer(...) is attached at app or window root and the model type is included.@Attribute(.unique) or #Unique constraints and rely on insert-upsert behavior..cascade vs .nullify) and check for unbounded delete(model:where:).isUndoEnabled: true and that changes are saved via mainContext (not only background context).cloudKitDatabase if multiple containers exist.fetchHistory) with token + author filtering.historyTokenExpired appears:
FetchDescriptor settings.@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
RootView()
}
.modelContainer(for: [Trip.self, Accommodation.self])
}
}
let config = ModelConfiguration(isStoredInMemoryOnly: false)
let container = try ModelContainer(
for: Trip.self,
Accommodation.self,
configurations: config
)
struct TripListView: View {
@Query private var trips: [Trip]
init(searchText: String) {
let predicate = #Predicate<Trip> {
searchText.isEmpty || $0.name.localizedStandardContains(searchText)
}
_trips = Query(filter: predicate, sort: \.startDate, order: .forward)
}
var body: some View { List(trips) { Text($0.name) } }
}
do {
try modelContext.delete(
model: Trip.self,
where: #Predicate { $0.endDate < .now },
includeSubclasses: true
)
try modelContext.save()
} catch {
// Handle delete and save failures.
}
references/modeling-and-schema.mdreferences/model-context-and-lifecycle.mdreferences/querying-and-fetching.mdreferences/relationships-and-inheritance.mdreferences/migrations-and-history.mdreferences/cloudkit-sync.mdreferences/core-data-adoption.mdreferences/concurrency-and-actors.mdreferences/troubleshooting-and-updates.mdreferences/implementation-playbooks.mdfetchLimit, offsets, identifier-only fetches) for scalability.ModelConfiguration for environment-specific behavior (in-memory tests, CloudKit, app groups, read-only stores).cascade, nullify, and others).sickn33/antigravity-awesome-skills
moizibnyousaf/ai-agent-skills
github/awesome-copilot