swiftdata-patterns

Model and manage SwiftData persistence patterns for iOS 17+ and macOS 14+ projects.

4|1|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/AutisticAF/claude-code-apple-dev-plugin --skill swiftdata-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata-patterns
Source: https://github.com/AutisticAF/claude-code-apple-dev-plugin/tree/main/skills/swiftdata-patterns
Command: npx skills add https://github.com/AutisticAF/claude-code-apple-dev-plugin --skill swiftdata-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides practical patterns and guidance for modeling, querying, configuring, and migrating relational data using SwiftData so developers can avoid common pitfalls and build reliable persistence layers for Apple platform apps.

Core Features & Use Cases

  • Model design: Best practices for declaring @Model reference types, attributes, transient properties, and sensible initializers.
  • Relationships & consistency: Guidance on Relationship delete rules, inverse declarations, and keeping the object graph consistent.
  • Queries & predicates: Examples for @Query, FetchDescriptor usage, SortDescriptor composition, and type-safe predicate construction.
  • Container configuration & sync: Instructions for ModelContainer setup, in-memory previews, on-disk stores, and CloudKit-backed configurations.
  • Migration & background work: VersionedSchema and SchemaMigrationPlan patterns, lightweight versus custom migrations, and background persistence using ModelActor.

Quick Start

Ask the skill to review your SwiftData model files and generate concrete Model, relationship, query, and migration recommendations for your app.

Frequently Asked Questions about swiftdata-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure a SwiftData ModelContainer for CloudKit sync?

Configuring a SwiftData ModelContainer for CloudKit sync requires specifying a CloudKit-backed configuration during container initialization. This skill provides instructions for on-disk stores, in-memory previews, and CloudKit-backed configurations.

What is the best way to define SwiftData relationships and delete rules?

Defining SwiftData relationships and delete rules requires declaring inverse relationships and setting sensible delete rules to keep the object graph consistent. This skill provides guidance on Relationship delete rules, inverse declarations, and object graph consistency.

How do I migrate a SwiftData schema using VersionedSchema?

Migrating a SwiftData schema using VersionedSchema involves defining VersionedSchema types and a SchemaMigrationPlan to map changes between versions. This skill covers VersionedSchema and SchemaMigrationPlan patterns, including lightweight versus custom migrations.

How do I write type-safe predicates for SwiftData FetchDescriptor queries?

Writing type-safe predicates for SwiftData FetchDescriptor queries involves constructing predicate expressions and composing SortDescriptor objects. This skill provides examples for @Query, FetchDescriptor usage, SortDescriptor composition, and type-safe predicate construction.

Does SwiftData work with background persistence using ModelActor?

SwiftData supports background persistence using ModelActor to execute database operations off the main thread. This skill includes patterns for background persistence via ModelActor alongside container configuration and migration planning.

When do I need custom SwiftData migrations instead of lightweight migrations?

You need custom SwiftData migrations instead of lightweight migrations when schema changes require complex data transformations or custom logic. This skill details VersionedSchema and SchemaMigrationPlan patterns, distinguishing between lightweight and custom migration approaches.