swiftdata

Define @Model entities, store data, and run reactive SwiftUI queries with #Predicate.

Updated May 10, 2026
One-click install
npx skills add https://github.com/FelixRauch/medat-figuren --skill swiftdata-felixrauch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata
Source: https://github.com/FelixRauch/medat-figuren/tree/main/.agents/skills/swiftdata
Command: npx skills add https://github.com/FelixRauch/medat-figuren --skill swiftdata-felixrauch

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

SwiftData removes the friction of building persistence, fetching, and schema evolution in modern iOS apps by providing a unified Swift-native workflow.

Core Features & Use Cases

  • Model definitions with @Model and attributes: Define persistent model classes, uniqueness, external storage, and relationships in a way that’s compatible with SwiftUI.
  • Reactive querying in SwiftUI with @Query: Fetch and auto-update views using filters, sort descriptors, and fetch descriptors designed for SwiftData’s predicate system.
  • CRUD and migrations you can trust: Insert, update, delete, batch process, and evolve schemas using VersionedSchema with SchemaMigrationPlan, including concurrency patterns with @ModelActor.

Quick Start

Implement a SwiftData @Model type, attach your SwiftUI views using .modelContainer and @Query, and use FetchDescriptor or #Predicate for efficient reads and updates.

Frequently Asked Questions about swiftdata

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

FAQPage Schema
How do I persist and query app data using SwiftData in SwiftUI?

To persist and query app data with SwiftData, define @Model entities and attach them to your views using .modelContainer. You can then fetch and auto-update views reactively with @Query and FetchDescriptor.

How does SwiftData handle schema migration when updating model entities?

SwiftData handles schema migration using VersionedSchema and SchemaMigrationPlan. This allows you to evolve your model definitions over time, ensuring structured data remains compatible across app updates without manual database scripts.

Can I use SwiftData with CloudKit for automatic sync?

Yes, SwiftData supports optional CloudKit sync. By configuring your ModelContainer appropriately, you can enable automatic synchronization of your @Model entities across a user's iCloud-connected devices.

How do I perform background data work safely with SwiftData?

For safe background work in SwiftData, use @ModelActor to maintain concurrency boundaries. Pass PersistentIdentifier across actors instead of crossing @Model objects directly, ensuring safe concurrent processing of structured data.

What is the best way to filter fetched records in a SwiftData app?

The best way to filter records in SwiftData is using #Predicate within a FetchDescriptor. This integrates with SwiftData's predicate system to execute efficient, type-safe queries on your local storage.

Why do I need ModelContainer and ModelContext in my SwiftData implementation?

ModelContainer and ModelContext are required in SwiftData to correctly configure your persistence stack. The container initializes the storage schema, while the context manages the lifecycle of @Model objects for CRUD operations.