swiftdata

Implement SwiftData persistence, queries, and VersionedSchema migrations for iOS models.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/DFly7/iOS-FastAPI-Supabase-AI --skill swiftdata-dfly7
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata
Source: https://github.com/DFly7/iOS-FastAPI-Supabase-AI/tree/main/.agents/skills/swiftdata
Command: npx skills add https://github.com/DFly7/iOS-FastAPI-Supabase-AI --skill swiftdata-dfly7

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Managing structured local data, reactive queries, schema evolution, and safe background operations in modern iOS apps can be error-prone and time consuming. This guidance centralizes best practices for defining persistent models, configuring storage containers, writing predicates and fetch descriptors, performing migrations, and integrating with SwiftUI and CloudKit so data remains consistent and safe across actors and processes.

Core Features & Use Cases

  • Model definition and relationships guidance including attribute options, external storage, transient properties, and uniqueness patterns for reliable persistence.
  • Container and configuration patterns covering in-memory previews, named configurations, CloudKit sync, app group storage, and coexistence with existing Core Data stores.
  • Querying and data access patterns: @Query usage in SwiftUI, FetchDescriptor and SortDescriptor options, complex #Predicate constructs, batched enumeration, and performance best practices.
  • Concurrency and migrations: using @ModelActor for background work, passing PersistentIdentifier across boundaries, VersionedSchema and SchemaMigrationPlan examples for lightweight and custom migration stages.
  • Real-world scenarios include migrating a Core Data store to SwiftData, implementing CloudKit sync-safe models, or building efficient background import pipelines.

Quick Start

Define your @Model classes, create a ModelContainer with a suitable ModelConfiguration, run a SchemaMigrationPlan if needed, and validate queries and background handlers using @ModelActor.

Frequently Asked Questions about swiftdata

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

FAQPage Schema
How do I define SwiftData model relationships and configure a ModelContainer for iOS apps?

SwiftData model definition involves using the @Model macro to establish classes, configure attribute options, and set up relationships. You then initialize a ModelContainer with a suitable ModelConfiguration to manage storage, enabling reliable persistence and data access in iOS apps.

Does SwiftData support Core Data coexistence and CloudKit sync?

Yes, SwiftData supports CloudKit sync and Core Data coexistence. You can configure named configurations, utilize app group storage, and define CloudKit sync-safe models to ensure data remains consistent across actors and processes during integration.

What is the best way to handle SwiftData background operations and actor isolation?

For SwiftData background operations, use the @ModelActor macro to ensure safe actor isolation. You can pass PersistentIdentifier across boundaries to execute background work efficiently while maintaining strict data integrity and concurrency safety.

How do I perform SwiftData schema migrations using VersionedSchema?

SwiftData schema migrations utilize VersionedSchema and SchemaMigrationPlan to transition between data models. You implement lightweight and custom migration stages to evolve your schema safely while preserving existing local data during app updates.

Why are my SwiftUI @Query fetch descriptors not returning expected SwiftData results?

SwiftUI @Query fetch descriptors require correctly configured SortDescriptor options and complex #Predicate constructs to filter results accurately. Validate your fetch descriptor logic, ensure batched enumeration is properly applied, and check performance best practices for reliable querying.

Can I migrate an existing Core Data store to SwiftData?

Migrating a Core Data store to SwiftData involves configuring coexistence between the existing store and the new ModelContainer. You define persistent models, validate schema compatibility, and execute migration plans to ensure structured local data transitions safely.