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.
91%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
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.
Core Data contexts are bound to queues: viewContext runs on the main queue, while background tasks use newBackgroundContext().
context.perform(_:) or context.performAndWait(_:).NSManagedObject instances between contexts or threads; pass NSManagedObjectID and re-fetch via existingObject(with:).automaticallyMergesChangesFromParent = true and configure mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy on viewContext.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(with: id) as? CDTrip else { return }
trip.name = name
if context.hasChanges { try context.save() }
}
}Drives UI collections from an NSFetchRequest with automatic change tracking:
controller(_:didChangeContentWith:)) on iOS 13+ to animate UI changes.deleteCache(withName:) before changing predicate or sort descriptors, or pass cacheName: nil.NSBatchInsertRequest, NSBatchUpdateRequest, and NSBatchDeleteRequest execute directly at the SQLite level, bypassing managed object contexts.
resultType = .objectIDs / .resultTypeObjectIDs.NSManagedObjectContext.mergeChanges(fromRemoteContextSave:into:).Deny).Track store modifications across app extensions, widgets, and processes:
NSPersistentHistoryTrackingKey: true in store options.NSPersistentHistoryChangeRequest and merge them into local contexts.NSStagedMigrationManager with lightweight and custom stages (NSCustomMigrationStage) for deterministic upgrades. Read references/staged-migration.md.@Attribute(originalName:). Route pure SwiftData work to the swiftdata skill.Use NSInMemoryStoreType for deterministic unit testing. Share a single compiled NSManagedObjectModel instance across tests to prevent duplicate entity runtime errors.
NSManagedObjectID and refetch with existingObject(with:).if context.hasChanges.mergePolicy causes conflict save crashes. Set NSMergeByPropertyObjectTrumpMergePolicy.@unchecked Sendable.NSPersistentContainer created once and shared across the appperform(_:) or performAndWait(_:)NSManagedObject instances cross thread or context boundariesviewContext.automaticallyMergesChangesFromParent is enabledmergePolicy configured on contexts to handle conflicts cleanlymergeChangesNSFetchedResultsController requests include explicit sort descriptorsNSManagedObjectModelthienqo/ios-skills
6bf8b62
Canonical home
since May 23, 2026
Also appears in
on Sep 6, 2026
since May 22, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.