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 skills add https://github.com/rshankras/claude-code-apple-skills --skill swiftdata-architecture
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.mdquery-patterns.mdrepository-pattern.mdperformance.mdGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
Take rshankras/swiftdata-architecture from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.