Back to Skills

swiftdata

Implement, review, or improve data persistence using SwiftData. Use when defining @Model classes with @Attribute, @Relationship, @Transient, @Unique, or @Index; when querying with @Query, #Predicate, FetchDescriptor, or SortDescriptor; when configuring ModelContainer and ModelContext for SwiftUI or background work with @ModelActor; when planning schema migrations with VersionedSchema and SchemaMigrationPlan; when setting up CloudKit sync with ModelConfiguration; or when coexisting with or migrat

741stars40forksUpdated 6/15/2026

Security Assessment

Low Risk(70/100)

Detected risks:

Secret Exposure([references/swiftdata-advanced.md] Token =)
Security Score70/100

About swiftdata

This skill provides comprehensive guidance for implementing data persistence in iOS applications using SwiftData, Apple's modern data framework introduced in iOS 17 and refined through iOS 26. It addresses the challenge of building robust, type-safe data models with automatic persistence, CloudKit synchronization, and efficient querying capabilities. The skill helps developers transition from Core Data to SwiftData's declarative API or build new persistence layers from scratch using Swift's modern language features including macros, structured concurrency, and property wrappers.

The skill covers the full spectrum of SwiftData capabilities, from defining models with @Model, @Attribute, @Relationship, and @Transient macros to configuring ModelContainer for local or cloud-synced storage. It provides detailed guidance on querying data using @Query property wrappers, #Predicate expressions, FetchDescriptor, and SortDescriptor. Advanced topics include schema versioning with VersionedSchema, migration planning with SchemaMigrationPlan, background processing with @ModelActor, and proper CloudKit sync configuration including required app entitlements. The skill also addresses model inheritance (iOS 26+), compound uniqueness constraints with #Unique (iOS 18+), and attribute options like external storage and spotlight integration.

This skill is designed for iOS developers building applications that require structured data persistence, whether creating new projects or migrating from Core Data. It's particularly valuable for teams implementing features like offline-first architectures, multi-device sync via CloudKit, complex data relationships, or apps requiring schema evolution over time. The skill includes a review checklist and common mistakes section to help both implement new code and audit existing SwiftData implementations for correctness, performance, and maintainability.

FAQ

What iOS versions and Swift versions does this skill cover?

This skill covers SwiftData for iOS 17 through iOS 26+ with Swift 6.3. It includes version-specific features like compound uniqueness constraints (#Unique) and unidirectional relationships in iOS 18+, and model inheritance in iOS 26+.

Can I use SwiftData alongside existing Core Data code?

Yes, the skill explicitly covers coexisting with or migrating from Core Data. SwiftData can work alongside Core Data in the same application, allowing gradual migration paths.

Do I need special Xcode configuration for CloudKit sync?

Yes, CloudKit sync requires proper app entitlements beyond just ModelConfiguration. You must enable the iCloud capability with CloudKit in your Xcode target, select the intended container, and enable Background Modes with Remote notifications. The skill emphasizes reviewing these capabilities before schema implementation.

What types of data can SwiftData persist?

SwiftData supports Swift's primitive types (Bool, Int, Float, Double, String), Foundation types (Date, Data, URL, UUID, Decimal), collections (Array, Dictionary, Set), Codable enums and structs, and relationships to other @Model classes. Large binary data can use @Attribute(.externalStorage) for optimization.

How do I handle concurrent data operations safely?

The skill covers using @ModelActor for safe background data operations with SwiftData. This ensures proper isolation and prevents data races when performing work outside the main actor context, following Swift's structured concurrency model.

All Files

7 files
references/swiftdata-queries.md17.8 KB
View
references/core-data-coexistence.md15.4 KB
View
references/swiftdata-advanced.md25.4 KB
View
evals/evals.json3.8 KB
View
SKILL.md13.8 KB
View
references/indexing.md2.0 KB
View
references/predicate-pitfalls.md2.7 KB
View

Install swiftdata

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill