# swiftdata

Gives the agent a working reference for SwiftData so persistence code on Swift 6.3 comes out right the first time.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 4100 installs · ★ 1237
- Author: dpearson2699
- License: LicenseRef-Unknown · policy=link-only · description only; the file stays with the author
- Source: https://github.com/dpearson2699/swift-ios-skills/tree/HEAD/skills/swiftdata/SKILL.md
- Updated: 2026-07-31
- HTML: https://affpapa.org/en/nevibecode/skills/swiftdata

## What it does

The skill loads a guide the agent reads before touching your data layer. It covers `@Model` classes, `@Attribute` options such as `.externalStorage` and `.unique`, delete rules on `@Relationship`, and compound keys declared with `#Unique`. Separate sections handle `@Query` in SwiftUI, `#Predicate`, `FetchDescriptor`, plus schema versioning with `VersionedSchema` and `SchemaMigrationPlan`.

CloudKit gets its own treatment. Before advising on sync, the agent checks that the target has the iCloud capability with CloudKit and the right container, and that Background Modes includes remote notifications. It also flags schema traits that break sync. Model objects stay tied to their context and actor, so the guide has you pass a `PersistentIdentifier` across actors instead of the instance.

The requirements are iOS 26+ and Swift 6.3. Model inheritance and the newer syntax will not build on older toolchains. For background work there is a `@ModelActor` section. Batch deletes deserve care: the skill tells you to run the exact predicate against a throwaway copy of the store first, then refetch and check counts, because a wrong `#Predicate` removes rows you meant to keep.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swiftdata -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/swiftdata/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/swiftdata/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swiftdata -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/swiftdata/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swiftdata -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/swiftdata/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install dpearson2699/swift-ios-skills swiftdata
```

2. **Manually: put the files in place**
- File: `.github/skills/swiftdata/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swiftdata -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/dpearson2699/swift-ios-skills --path skills/swiftdata
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/swiftdata/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swiftdata -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/dpearson2699/swift-ios-skills/tree/HEAD/skills/swiftdata/SKILL.md

## When to use it
- declare a model with external storage for images and cascade deletes on a relationship
- filter a SwiftUI list by a search string through `#Predicate`
- move a store to a new schema version without dropping user data
- turn on CloudKit sync and confirm the schema allows it
- run writes on a background actor without passing model objects between threads

## Example prompts
- Write a `@Model` class `Trip` with a name, destination, start and end dates, and a cascade-deleting relationship to accommodation
- Build a SwiftUI screen that lists favorite trips via `@Query`, sorted by `startDate` descending
- Plan a store migration using `VersionedSchema` and `SchemaMigrationPlan`

## Similar
- [vercel-react-native-skills](https://affpapa.org/en/nevibecode/skills/vercel-react-native-skills.md) — skill · 255200 installs
- [animate-expo](https://affpapa.org/en/nevibecode/skills/animate-expo.md) — skill · 137900 installs
- [mobile-native](https://affpapa.org/en/nevibecode/skills/mobile-native.md) — skill · 86600 installs
- [aso](https://affpapa.org/en/nevibecode/skills/aso.md) — skill · 75400 installs
- [swiftui-pro](https://affpapa.org/en/nevibecode/skills/swiftui-pro.md) — skill · 35200 installs
- [orca-emulator](https://affpapa.org/en/nevibecode/skills/orca-emulator.md) — skill · 5800 installs

## Other versions with the same name
- [swiftdata · prisma-labs-dev](https://affpapa.org/en/nevibecode/skills/prisma-labs-dev-swiftdata.md) — 468 installs

From the same set: [dpearson2699/swift-ios-skills](https://affpapa.org/en/nevibecode/by/dpearson2699/swift-ios-skills.md) — 86 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
