swiftdata

Define SwiftData models and query persisted data with @Model and @Query.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/onymchat/onym-ios --skill swiftdata-onymchat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata
Source: https://github.com/onymchat/onym-ios/tree/main/.claude/skills/swiftdata
Command: npx skills add https://github.com/onymchat/onym-ios --skill swiftdata-onymchat

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

SwiftData streamlines the persistence and querying of structured data in iOS apps, enabling you to model, store, and retrieve data with Swift-friendly APIs.

Core Features & Use Cases

  • Define models using @Model with @Attribute, @Relationship, @Transient, @Unique, and @Index to model domain data.
  • Query data using @Query, #Predicate, FetchDescriptor, and SortDescriptor, and integrate with SwiftUI via ModelContainer and ModelContext.
  • Plan and apply migrations via VersionedSchema and SchemaMigrationPlan, and configure CloudKit sync with ModelConfiguration for iCloud-backed stores.
  • Coexistence with Core Data for gradual migrations and shared stores when migrating from Core Data.

Quick Start

Define a @Model, configure a ModelContainer, insert data, and fetch it to verify persistence.

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 data in an iOS app using SwiftData?

SwiftData persistence and querying requires defining @Model classes with @Attribute and @Relationship, configuring a ModelContainer, and using @Query with #Predicate and FetchDescriptor to retrieve data within SwiftUI contexts.

How does SwiftData handle schema migrations during app updates?

SwiftData migrations require defining a VersionedSchema and a SchemaMigrationPlan to manage schema evolution, allowing structured data stores to upgrade safely when model definitions change across app versions.

Can I sync SwiftData with iCloud using CloudKit?

Yes, SwiftData CloudKit sync is configured using ModelConfiguration for iCloud-backed stores, enabling structured data to synchronize automatically across a user's iOS devices through their iCloud account.

Does SwiftData work alongside Core Data for gradual migrations?

Yes, SwiftData supports coexistence with Core Data for gradual migrations and shared stores, allowing iOS apps to transition persistence layers incrementally rather than rewriting data management architecture entirely.

How do I define relationships and constraints in SwiftData models?

SwiftData model definition uses @Model classes annotated with @Relationship for data connections, @Attribute for property customization, @Unique for constraints, and @Index to optimize query performance.

Can I use SwiftData in background tasks outside of SwiftUI?

Yes, SwiftData querying and persistence operations are usable from background tasks, not just SwiftUI contexts, by interacting directly with the configured ModelContainer and ModelContext to manage data asynchronously.