Expert Core Data decisions for iOS/tvOS: when Core Data vs alternatives, context architecture for multi-threading, migration strategy selection, and performance optimization trade-offs. Use when choosing persistence layer, debugging save failures, or optimizing fetch performance. Trigger keywords: Core Data, NSManagedObject, NSPersistentContainer, NSFetchRequest, FetchRequest, migration, lightweight migration, background context, merge policy, faulting
View on GitHubKaakati/rails-enterprise-dev
reactree-ios-dev
January 25, 2026
Select agents to install to:
npx add-skill https://github.com/Kaakati/rails-enterprise-dev/blob/main/plugins/reactree-ios-dev/skills/core-data-patterns/SKILL.md -a claude-code --skill core-data-patternsInstallation paths:
.claude/skills/core-data-patterns/# Core Data Patterns — Expert Decisions
Expert decision frameworks for Core Data choices. Claude knows NSPersistentContainer and fetch requests — this skill provides judgment calls for when Core Data fits and architecture trade-offs.
---
## Decision Trees
### Core Data vs Alternatives
```
What's your persistence need?
├─ Simple key-value storage
│ └─ UserDefaults or @AppStorage
│ Don't use Core Data for preferences
│
├─ Flat list of Codable objects
│ └─ Is query complexity needed?
│ ├─ NO → File-based (JSON/Plist) or SwiftData
│ └─ YES → Core Data or SQLite
│
├─ Complex relationships + queries
│ └─ How many objects?
│ ├─ < 10,000 → SwiftData (simpler) or Core Data
│ └─ > 10,000 → Core Data (more control)
│
├─ iCloud sync required
│ └─ NSPersistentCloudKitContainer
│ Built-in sync with Core Data
│
└─ Cross-platform (non-Apple)
└─ SQLite directly or Realm
Core Data is Apple-only
```
**The trap**: Using Core Data for simple lists. If you don't need relationships, queries, or undo, consider simpler options like SwiftData or file storage.
### Context Architecture
```
How many contexts do you need?
├─ Simple app, UI-only operations
│ └─ viewContext only
│ Single context for reads and small writes
│
├─ Background imports/exports
│ └─ viewContext + newBackgroundContext()
│ Background for writes, viewContext for UI
│
├─ Complex with multiple writers
│ └─ Parent-child context hierarchy
│ Rarely needed — adds complexity
│
└─ Sync with server
└─ Dedicated sync context
performBackgroundTask for sync operations
```
### Migration Strategy
```
What changed in your model?
├─ Added optional attribute
│ └─ Lightweight migration (automatic)
│
├─ Renamed attribute/entity
│ └─ Lightweight with mapping model hints
│ Set renaming identifier in model
│
├─ Changed attribute type
│ └─ Depends on conversion possibility
│ Int → String: lightweight
│ String → Date: may need custom
│
├─ Added required attribute