swiftdata

Explain SwiftData APIs like @Model, ModelContext, @Query, and schema migrations.

Updated May 6, 2026
One-click install
npx skills add https://github.com/Roy-wonji/claude-config --skill swiftdata-roy-wonji
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata
Source: https://github.com/Roy-wonji/claude-config/tree/main/skills/apple-skills/skills/swiftdata
Command: npx skills add https://github.com/Roy-wonji/claude-config --skill swiftdata-roy-wonji

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

When you’re building with SwiftData, you need accurate answers for APIs like @Model, ModelContext, @Query, and schema migration details without wasting time searching external docs.

Core Features & Use Cases

  • SwiftData API lookup: Rapidly find the right concepts for SwiftData types and macros.
  • Query-centric guidance: Clarify how to fetch and keep results in sync using @Query and related fetching mechanisms.
  • Model + persistence lifecycle: Explain how @Model turns classes into persistent models and how ModelContext manages inserts, deletes, and saves.
  • Migrations & schema evolution: Help interpret how schema versions and migration plans work at a high level.

Quick Start

Ask the skill: "How do I define a SwiftData model with @Model and fetch objects using @Query with a filter and sort?"

Frequently Asked Questions about swiftdata

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

FAQPage Schema
How do I define a SwiftData model with @Model and fetch objects using @Query?

Define a SwiftData model by applying the @Model macro to a class, then use @Query in SwiftUI to fetch and filter those persistent objects with reactive updates. The skill provides focused API guidance and reference file paths for deeper details.

What is the best way to perform CRUD operations with ModelContext in a SwiftUI app?

ModelContext manages the persistence lifecycle for your SwiftData objects, handling inserts, deletes, and saves. You use it within your SwiftUI app to perform CRUD operations and keep your local database synchronized with your view state.

How does SwiftData schema migration work when updating persistent models?

SwiftData schema migration works by defining schema versions and creating migration plans to transition between them. This skill helps interpret how these concepts work at a high level to evolve your persistent models safely.

Can I use @Query to filter and sort SwiftData records in SwiftUI?

You can use @Query in SwiftUI to fetch SwiftData records while applying custom filters and sort descriptors. It keeps your view automatically updated whenever the underlying data changes, ensuring reactive UI synchronization.

Why do I need to use @Model for SwiftData persistence instead of regular Swift classes?

You need @Model because it transforms standard Swift classes into persistent models that SwiftData can track and store. This macro provides the necessary persistence lifecycle management that regular classes lack for database operations.