skills/macos/swiftdata-architecture/SKILL.md
Deep dive into SwiftData design patterns and best practices. Covers schema design, query patterns, repository pattern, and performance optimization. Use when designing data models or improving SwiftData usage.
npx skillsauth add rshankras/claude-code-apple-skills swiftdata-architectureInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a macOS development expert specializing in SwiftData persistence. You help developers design efficient data models, write performant queries, and build testable data layers.
Guide developers through SwiftData architecture decisions, from schema design to query optimization to data layer abstraction. Focus on patterns that work well with SwiftUI and modern Swift concurrency.
| Question | Answer | |----------|--------| | Should I use SwiftData or Core Data? | SwiftData for new projects | | @Query or FetchDescriptor? | @Query in views, FetchDescriptor in services | | Should I use a repository pattern? | Yes, if you need testability or data source flexibility | | How to handle large datasets? | Pagination + background context + batch operations | | Relationships: optional or required? | Default to optional unless the model is invalid without it |
// Wrong - duplicate entries on re-import
@Model class Contact {
var email: String
var name: String
}
// Right - prevent duplicates
@Model class Contact {
#Unique<Contact>([\.email])
var email: String
var name: String
}
// Wrong - loads all properties of all records
let descriptor = FetchDescriptor<Document>()
let allDocs = try modelContext.fetch(descriptor)
// Right - fetch only what you need
var descriptor = FetchDescriptor<Document>()
descriptor.propertiesToFetch = [\.title, \.createdAt]
descriptor.fetchLimit = 50
let docs = try modelContext.fetch(descriptor)
// Wrong - model from main context modified on background
let doc = documents.first!
Task.detached {
doc.title = "Updated" // Thread safety violation!
}
// Right - use background ModelContext
let container = modelContext.container
Task.detached {
let bgContext = ModelContext(container)
let descriptor = FetchDescriptor<Document>(predicate: #Predicate { $0.id == docID })
if let doc = try bgContext.fetch(descriptor).first {
doc.title = "Updated"
try bgContext.save()
}
}
For each issue found:
Load these modules as needed:
Schema Design: schema-design.md
Query Patterns: query-patterns.md
Repository Pattern: repository-pattern.md
Performance: performance.md
development
US web checkout via the StoreKit External Purchase Link entitlement — currently 0% Apple commission (litigation ongoing), how to ship it safely, and how to architect for a commission flip so a future ruling is a config change, not a rewrite. Use when adding external purchase links, weighing web checkout vs IAP, or planning US-storefront pricing strategy.
tools
Revenue beyond the single-app price tag — own-app bundles, Family Sharing as a conversion lever, cross-developer bundles & suites, and institutional licensing via Group Purchases / Apple School & Business Manager. Use when a developer has multiple apps, a subscription worth sharing, complementary indie partners, or school/clinic/business buyers.
testing
Run a structured accessibility audit on an iOS/macOS app — automated XCUITest audits, Accessibility Inspector, manual VoiceOver/Dynamic Type passes, and App Store Accessibility Nutrition Label evaluation. Use before release, when preparing Nutrition Label declarations, or for EU Accessibility Act compliance.
tools
Stage-by-stage audit of an app's App Store growth machinery against a 54-item P0–P9 playbook — every item scored from an App Store Connect MCP call, a codebase check, or an explicit question to the user, then routed to the skill or command that fixes it. Read-only on App Store Connect. Use for a growth audit or scorecard, a pre-launch growth plan, a quarterly re-audit, or "which growth levers am I missing."