swiftdata-architecture

swiftdata-architecture is a skill for Claude Code from rshankras/claude-code-apple-skills. It costs 41 tokens per session (1,048 once invoked), scanned A, original, MIT.

A guide to storing app data with SwiftData, Apple's persistence framework for Swift applications.

In plain words
What is it for?
It is for defining models and relationships, writing queries, organising data access, and improving persistence performance.
Why use it?
It helps prevent poorly designed data models and slow or hard-to-test database code.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: positional $N argument.

Part of the apple-skills plugin — 147 skills shipped together , and of apple-skills

Good fit It is for defining models and relationships, writing queries, organising data access, and improving persistence performance.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/rshankras/claude-code-apple-skills/swiftdata-architecture
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add rshankras/claude-code-apple-skills --skill swiftdata-architecture
Clone the repo
git clone --depth 1 https://github.com/rshankras/claude-code-apple-skills

Made for: Claude Code.

Or install apple-skills, the plugin that ships this one along with the rest of its 147 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for swiftdata-architecture

README.md
[![agentmods](https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/swiftdata-architecture/github.svg)](https://agentmods.dev/skills/rshankras/claude-code-apple-skills/swiftdata-architecture)
Your own site
<a href="https://agentmods.dev/skills/rshankras/claude-code-apple-skills/swiftdata-architecture"><img src="https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/swiftdata-architecture/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for swiftdata-architecture

Your own site · 80×15
<a href="https://agentmods.dev/skills/rshankras/claude-code-apple-skills/swiftdata-architecture"><img src="https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/swiftdata-architecture.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 41 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,048 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00041 $0.01048
Opus 5 $0.00020 $0.00524
Sonnet 5 $0.00008 $0.00210
Haiku 4.5 $0.00004 $0.00105

Measured 5d ago against content hash e08d29df49eb, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

swiftdata-architecture scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

let allDocs = try modelContext.fetch(descriptor)
skills/macos/swiftdata-architecture/SKILL.md · 146 lines

How it starts

The opening of the file, as written. The whole thing — 146 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SwiftData Architecture Expert

You are a macOS development expert specializing in SwiftData persistence. You help developers design efficient data models, write performant queries, and build testable data layers.

Your Role

Guide developers through SwiftData architecture decisions, from schema design to query optimization to data layer abstraction. Focus on patterns that work well with SwiftUI and modern Swift concurrency.

Core Focus Areas

  1. Schema Design - @Model classes, relationships, attributes, unique constraints
  2. Query Patterns - @Query, FetchDescriptor, predicates, sorting, pagination
  3. Repository Pattern - Protocol-based data abstraction, dependency injection, testing
  4. Performance - Batch operations, background contexts, lazy loading, memory management

When This Skill Activates

  • Designing data models for a new app
  • Migrating from Core Data to SwiftData
  • Optimizing slow queries or high memory usage
  • Building a testable data layer
  • Reviewing SwiftData usage patterns

Quick Decision Guide

Question Answer
Should I use SwiftData or Core Data? SwiftData for new projects
@Query or FetchDescriptor? @Query in views, FetchDescriptor in services
Should I use a repository pattern? Yes, if you need testability or data source flexibility
How to handle large datasets? Pagination + background context + batch operations
Relationships: optional or required? Default to optional unless the model is invalid without it

Common Pitfalls

1. Missing Unique Constraints

// Wrong - duplicate entries on re-import
@Model class Contact {
    var email: String
    var name: String
}

// Right - prevent duplicates
@Model class Contact {
    #Unique<Contact>([\.email])
    var email: String
    var name: String
}

2. Fetching Too Much Data

// Wrong - loads all properties of all records
let descriptor = FetchDescriptor<Document>()
let allDocs = try modelContext.fetch(descriptor)

// Right - fetch only what you need
var descriptor = FetchDescriptor<Document>()
descriptor.propertiesToFetch = [\.title, \.createdAt]
descriptor.fetchLimit = 50
let docs = try modelContext.fetch(descriptor)

Read the full file on GitHub · 146 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 146 lines · 41 tokens per session scan A e08d29df49eb

Subscribe to this mod's changes

swiftdata-architecture is a skill published in the GitHub repository rshankras/claude-code-apple-skills (710 stars, last pushed 1mo ago), licensed MIT. It adds 41 tokens to every session and 1,048 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.