swiftdata-expert-skill
Installation
SKILL.md
SwiftData Expert Skill
Overview
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.
Agent Behavior Contract (Follow These Rules)
- Identify the minimum deployment target before recommending APIs (notably
#Index,#Unique,HistoryDescriptor,DataStore, inheritance examples). - Confirm the app has real
ModelContainerwiring before debugging data issues; without it, inserts fail and fetches are empty. - Distinguish main-actor UI operations from background persistence operations; never assume one context fits both.
- Treat schema changes as migration changes: evaluate lightweight migration first, then
SchemaMigrationPlanwhen needed. - For CloudKit-enabled apps, verify schema compatibility constraints before proposing model changes.
- Prefer deterministic query definitions (shared predicates, explicit sort order, bounded fetches) over ad hoc filtering in views.
- Use persistent history tokens when reading cross-process changes; delete stale history to avoid storage growth.
- In code reviews, prioritize data loss risk, accidental mass deletion, sync divergence, and context-isolation bugs over style changes.