Core Data — Foundations Skill
Purpose
Route Core Data implementation tasks to the minimum required Core Data
Knowledge Contracts. v1 scope is subclassing NSManagedObject and choosing
an .xcdatamodeld Codegen mode with @NSManaged properties, standing up
and loading an NSPersistentContainer, performing CRUD through an
NSManagedObjectContext with basic thread confinement and a basic
parent-child context relationship, fetching with NSFetchRequest/
@FetchRequest, and NSDeleteRule/inverse-relationship referential
integrity -- not CloudKit sync, not migration, not
NSFetchedResultsController, not advanced multi-context concurrency, and
not SwiftData interop.
Routing
Load only the contracts relevant to the task. All paths relative to knowledge/core-data/.
- Subclassing
NSManagedObject; choosing a Codegen mode (Class Definition/Category+Extension/Manual-None); declaring@NSManagedattribute or relationship properties; or asking what Xcode's generated code does and doesn't synthesize -> model-definition.md - Constructing
NSPersistentContainer(name:); callingloadPersistentStores(completionHandler:)and handling its error; readingviewContext; configuring a store viaNSPersistentStoreDescription/persistentStoreDescriptions; or injecting a context with.environment(\.managedObjectContext, ...)-> persistent-container-setup.md - Inserting via
NSEntityDescription.insertNewObject(forEntityName:into:)or a generatedinit(context:); callingdelete(_:)/save(); checkinghasChanges; wrapping work inperform(_:)/performAndWait(_:); or setting up a basic parent-child context viaparent-> managed-object-context-crud.md - Building an
NSFetchRequest<T>with apredicate/sortDescriptors; callingcontext.fetch(_:); or declaring@FetchRequestin a SwiftUI view -> fetching-with-nsfetchrequest.md - Choosing an
NSDeleteRulevalue (.cascadeDeleteRule/.nullifyDeleteRule/.denyDeleteRule/.noActionDeleteRule); reasoning about what happens to related objects on delete; or diagnosing a relationship missing itsinverseRelationship-> relationships-and-delete-rules.md
Never load more than the contracts relevant to the specific question.
Stop Conditions
Stop and report if the requested topic has no matching Knowledge Contract in knowledge/core-data/ — do not guess or fall back to general knowledge.
NSPersistentCloudKitContainer/CloudKit sync — Deferred- Lightweight and mapping-model migration (
NSMigrationManager, versioned/mapping models) — Deferred NSFetchedResultsController— Deferred; do not fabricate its behavior fromfetching-with-nsfetchrequest- Multi-context concurrency beyond one parent-child relationship — Deferred
- SwiftData interop or migration (
@Model,ModelContainer,ModelContext) — owned byswiftdata; do not answer SwiftData questions from Core Data contracts or fabricate a shared API surface