Skip to content
SwiftSkills

Core Data with AI agents: stacks, contexts, migrations and audits

Install a dedicated Core Data skill so the agent builds an NSPersistentContainer stack, keeps NSManagedObjectContext work on the right queue, and plans lightweight or custom migrations — do not let it treat Core Data like SwiftData @Model/@Query, and add a data-model audit skill when relationships and migrations drift.

Last updated:

This page is about getting a coding agent to ship Core Data correctly: an NSPersistentContainer stack, queue-safe contexts, fetch and batch updates, model migration, and optional CloudKit sync. For @Model / @Query work, see SwiftData with AI agents. For Claude Code-only skill shopping lists, see Best Claude Code skills for SwiftUI.

What the agent has to get right

Core Data lets you "persist or cache data on a single device, or sync data to multiple devices with CloudKit." Agents that only know SwiftData will invent @Model types inside a Core Data project, share one context across queues, or rewrite the store on every launch.

Three layers show up in almost every PR:

  1. Stack — set up the stack with NSPersistentContainer as in Setting Up a Core Data Stack and Creating a Core Data Model.

  2. Contexts — keep NSManagedObjectContext work on the right queue; pass NSManagedObjectID between queues; use background contexts for imports (Loading and Displaying a Large Data Feed, Batch Processing).

  3. Migration and sync — version the model and prefer lightweight migration when possible; for iCloud use NSPersistentCloudKitContainer and follow Synchronizing a Local Store to the Cloud / Consuming Relevant Store Changes.

Rules worth adding to AGENTS.md or CLAUDE.md:

Core Data: use NSPersistentContainer (or NSPersistentCloudKitContainer). Never pass NSManagedObject or a context across queues — pass NSManagedObjectID and use perform(_:). Prefer lightweight migration; write a mapping model only when needed. Do not invent SwiftData @Model APIs in a Core Data target.

Step 1: install a Core Data skill

Ask the agent to:

  1. Install Core Data Expert (npx skills add https://github.com/AvdLee/Core-Data-Agent-Skill) as the primary Core Data coach.

  2. Optionally install Swift and Apple platform skills (fal3) and select swiftdata-core-data-migrations when a store upgrade dominates.

  3. Swift Skills Pro (/plugin install core-data-pro@swift-skills-pro or npx swift-skills-cli install) and Radar Suite (/plugin install radar-suite@radar-suite) add a focused core-data-pro skill and a cross-file data-model audit.

Honest limit: do not install every persistence pack at once. One dedicated Core Data skill plus fal3 when migrations dominate is enough for most PRs.

Step 2: stack and contexts, not SwiftData APIs

Point the agent at Apple's Setting Up a Core Data Stack and NSPersistentContainer pages. Require:

  1. A real .xcdatamodeld (or programmatic model) loaded by the container — not ad-hoc JSON files pretending to be Core Data.

  2. A view context for UI reads and background contexts for imports; no shared mutable context across queues.

  3. Object IDs at queue boundaries; perform / performAndWait for context work.

  4. Batch inserts/deletes for large feeds per Apple's batch processing guidance — not one save() per row on the main queue.

Step 3: migrate before you sync

When the model changes:

  1. Add a new model version; enable lightweight migration when the change is inferable.

  2. Use a custom mapping / migration manager only when lightweight migration cannot express the transform.

  3. For CloudKit, start from NSPersistentCloudKitContainer and Apple's synchronizing / consuming-store-changes articles — do not roll a private CloudKit schema by hand next to an incompatible model.

Step 4: audit models across files after merge

After Radar Suite merges, run its data-model-radar skill on SwiftData and Core Data definitions when relationships, serialization or migration safety look wrong across modules. It is an audit router, not a substitute for Core Data Expert during stack setup.

Tools compared (4)

ToolBest forAgents (README)Install (README)LicenseStarsLast push
Core Data Expert (AvdLee)Dedicated Core Data skill: safe persistence, performance and schema migrationClaude Code, Cursor, Codexnpx skills add https://github.com/AvdLee/Core-Data-Agent-SkillMIT31814 Sep 2026 ⚠
Swift and Apple platform skills (fal3) (fal3)Collection including swiftdata-core-data-migrations for schema changes, store upgrades and persistence migrationsClaude Code, Codexgit clone https://github.com/fal3/claude-skills-collection.git then python3 scripts/install_skills.py --dest "$HOME/.agents/skills"MIT1928 Oct 2026
Swift Skills Pro (laxrajpurohit)core-data-pro: modeling, background contexts, fetch requests, batching and migration (plus 11 other Swift topics)Claude Code, Cursor, Codex, Windsurf/plugin marketplace add laxrajpurohit/swift-skills-pro then /plugin install core-data-pro@swift-skills-pro (or npx swift-skills-cli install)MIT618 Oct 2026
Radar Suite (Terryc21)Claude Code audit plugin; data-model-radar covers SwiftData/Core Data field completeness, relationships, migration safetyClaude Code/plugin marketplace add Terryc21/radar-suite then /plugin install radar-suite@radar-suiteApache-2.02020 Oct 2026

⚠ = no push for more than 4 weeks. fal3 was pushed on 28 Oct 2026. Core Data Expert (14 Sep) is older — verify API names against the current SDK before treating every tip as current.

Which one to pick:

  • Default Core Data coaching: Core Data Expert.

  • Store upgrade / migration-heavy PR: fal3 swiftdata-core-data-migrations.

  • Background contexts + batching after merge: Swift Skills Pro core-data-pro.

  • Cross-file model audit after merge: Radar Suite data-model-radar.

A prompt that keeps the agent honest

Setting up the agent itself: Claude Code for iOS development, Codex for iOS development or Cursor rules for SwiftUI.

Add an NSPersistentContainer stack with a view context and a background context for imports. Entities use NSManagedObject subclasses. Never pass managed objects across queues — pass object IDs. Add a new model version with lightweight migration for a renamed attribute. Do not introduce SwiftData @Model types in this target.

FAQ

What is Core Data for AI coding agents?
Core Data is Apple's framework to persist or cache data on a device and optionally sync with CloudKit. Agent skills teach Claude Code, Cursor or Codex to set up an NSPersistentContainer stack, keep NSManagedObjectContext work thread-safe, write fetch requests and batch updates, and migrate the model without corrupting the store.
How does this differ from the SwiftData guide?
The SwiftData with AI agents guide (queued) owns @Model, @Query, ModelActor and VersionedSchema. This page owns Core Data stacks, contexts, NSPersistentCloudKitContainer and Core Data migrations. Use a Core Data skill for NSManagedObject code; use a SwiftData skill when the project is already on SwiftData.
Should the agent pass NSManagedObject instances across queues?
No. Apple's Core Data stack and NSManagedObjectContext documentation treat contexts as queue-bound. Pass NSManagedObjectID values between queues, perform work with perform(_:) / performAndWait(_:), and keep UI reads on a view context. Skills that cover background contexts exist so the agent does not invent shared mutable contexts.
Which tool should I install first for Core Data?
Start with Core Data Expert (AvdLee) for safe persistence, performance and schema migration. Add fal3's swiftdata-core-data-migrations skill when a store upgrade dominates. Swift Skills Pro core-data-pro covers modeling, background contexts, fetch requests, batching and migration, and Radar Suite's data-model-radar audits SwiftData and Core Data models across files.
Does Radar Suite replace a Core Data expert skill?
No. Radar Suite is a Claude Code audit plugin that finds cross-file data-model bugs; it does not teach stack setup. Use Core Data Expert or core-data-pro to write the stack, then Radar Suite after merge when you want an audit of models, relationships and migration safety.