← ClaudeAtlas

core-datalisted

Build or review persistence in apps that still use Core Data, including managed objects, fetched results, batch operations, persistent history, staged migration, and concurrency. Use for Core Data-only work; route SwiftData adoption or coexistence to swiftdata.
thienqo/ios-skills · ★ 11 · Data & Documents · score 69
Install: claude install-skill thienqo/ios-skills
# Core Data Build and maintain data persistence using Core Data for apps that have not adopted SwiftData. Covers stack setup, concurrency, batch operations, NSFetchedResultsController, persistent history tracking, staged migration, and testing. ## Contents - [Stack Setup & Concurrency](#stack-setup--concurrency) - [NSFetchedResultsController](#nsfetchedresultscontroller) - [Batch Operations](#batch-operations) - [Persistent History Tracking](#persistent-history-tracking) - [Staged Migration & Coexistence](#staged-migration--coexistence) - [Testing](#testing) - [Common Mistakes](#common-mistakes) - [Review Checklist](#review-checklist) - [References](#references) ## Stack Setup & Concurrency Core Data contexts are bound to queues: `viewContext` runs on the main queue, while background tasks use `newBackgroundContext()`. - **Context Isolation**: Always wrap access in `context.perform(_:)` or `context.performAndWait(_:)`. - **Thread Crossing**: Never pass `NSManagedObject` instances between contexts or threads; pass `NSManagedObjectID` and re-fetch via `existingObject(with:)`. - **Automatic Merging**: Set `automaticallyMergesChangesFromParent = true` and configure `mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy` on `viewContext`. ```swift import CoreData func updateTrip(id: NSManagedObjectID, name: String) async throws { let context = CoreDataStack.shared.newBackgroundContext() try await context.perform { guard let trip = try context.existingObject