swiftdata

Implement SwiftData persistence with models, queries, and migrations for iOS apps.

3|Updated Mar 13, 2026
One-click install
npx skills add https://github.com/andrew-d/claude-skills --skill swiftdata-andrew-d
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata
Source: https://github.com/andrew-d/claude-skills/tree/main/plugins/swift-ios-skills--swift-core-skills/skills/swiftdata
Command: npx skills add https://github.com/andrew-d/claude-skills --skill swiftdata-andrew-d

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you implement, review, or improve data persistence in your iOS applications using SwiftData, ensuring your app's data is managed efficiently and reliably.

Core Features & Use Cases

  • Model Definition: Define your data models using the @Model macro, specifying attributes, relationships, and transient properties.
  • Data Persistence: Set up ModelContainer for your app's data store, including configurations for CloudKit sync or in-memory storage for previews.
  • CRUD Operations: Perform Create, Read, Update, and Delete operations on your data using ModelContext and FetchDescriptor.
  • Querying: Leverage @Query and #Predicate for powerful, declarative data fetching directly in SwiftUI views.
  • Schema Migration: Handle database schema evolution gracefully with VersionedSchema and SchemaMigrationPlan.
  • Concurrency: Manage data operations safely in background threads using @ModelActor.

Quick Start

Use the swiftdata skill to define a new @Model class named 'Task' with properties 'title' (String) and 'isCompleted' (Bool).

Frequently Asked Questions about swiftdata

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

FAQPage Schema
How do I set up ModelContainer for SwiftData persistence in a SwiftUI app?

To set up SwiftData persistence, initialize a ModelContainer with your schema and inject it into your SwiftUI view hierarchy. This configures the app's data store, supporting options like CloudKit sync or in-memory storage for previews.

How does querying data with @Query and #Predicate work in SwiftData?

Querying data in SwiftData uses the @Query property wrapper with #Predicate to declaratively fetch and filter records directly in SwiftUI views. This mechanism provides type-safe, expressive data fetching without manual fetch requests.

What is the best way to handle schema migration in SwiftData?

The best way to handle SwiftData schema migration is using VersionedSchema and SchemaMigrationPlan. These mechanisms allow you to define staged schema versions and execute custom migration logic to gracefully evolve your database.

Does SwiftData work with background threads and concurrency?

SwiftData handles background concurrency safely using the @ModelActor macro. This isolates data operations in background threads, ensuring safe ModelContext access without race conditions during intensive data tasks.

How do I define data models with relationships in SwiftData?

Defining SwiftData models uses the @Model macro with @Attribute and @Relationship annotations. This specifies persistent properties, unique constraints, and relational mappings between data classes for reliable storage.

Why use SwiftData over Core Data for iOS data persistence?

SwiftData offers modern, macro-driven data persistence with direct SwiftUI integration via @Query, reducing Core Data boilerplate. It provides type-safe predicates and simplified ModelContainer setup while retaining robust migration capabilities.