Core Data Expert

avdlee/core-data-agent-skill/core-data-expert

作者 avdlee855ca7d0df50无许可证315 个星标收录于 2026年10月8日更新于 2026年10月8日仓库3周前更新

Expert Core Data guidance (iOS/macOS): stack setup, fetch requests & NSFetchedResultsController, saving/merge conflicts, threading & Swift Concurrency, batch operations & persistent history, migrations, performance, and NSPersistentCloudKitContainer/CloudKit sync.

AI 生成的概览

为 iOS 和 macOS 提供面向生产的 Core Data 指导,涵盖堆栈搭建、抓取、线程、迁移、性能与 CloudKit 同步。

功能
该技能将 Core Data 问题路由到随附的参考文档,并为搭建、缺陷修复、迁移、性能和 CloudKit 问题提供分诊步骤。它给出上下文隔离、传递 NSManagedObjectID 而非托管对象、合并策略、批量操作和持久化历史记录等规则。它还把常见 Core Data 错误映射到相应的参考文件,并附有验证清单。
适用场景
适用于在 iOS 或 macOS 上构建或调试 Core Data 堆栈时,例如解决线程或跨上下文崩溃、迁移错误、合并冲突、批量操作未刷新界面或 CloudKit 同步问题。也适合规划抓取请求、并发模式或性能分析时使用。
运行要求
无需脚本或软件包;这是仅含说明的技能,附带参考文档。它假定使用者熟悉 Apple 的 Core Data 框架,部分主题还涉及 Swift Concurrency、CloudKit 和 Instruments。

Core Data Expert

Fast, production-oriented guidance for building correct, performant Core Data stacks and fixing common crashes.

Agent behavior contract (follow these rules)

  1. Determine OS/deployment target when advice depends on availability (iOS 14+/17+ features, etc.).
  2. Identify the context type before proposing fixes: view context (UI) vs background context (heavy work).
  3. Recommend NSManagedObjectID for cross-context/cross-task communication; never pass NSManagedObject instances across contexts.
  4. Prefer lightweight migration when possible; use staged migration (iOS 17+) for complex changes.
  5. When recommending batch operations, verify persistent history tracking is enabled (often required for UI updates).
  6. For CloudKit integration, remind developers that Production schema is immutable.
  7. Reference WWDC/external resources sparingly; prefer this skill’s references/.

First 60 seconds (triage template)

  • Clarify the goal: setup, bugfix, migration, performance, CloudKit?
  • Collect minimal facts:
    • platform + deployment target
    • store type (SQLite / in-memory) and whether CloudKit is enabled
    • context involved (view vs background) and whether Swift Concurrency is in use
    • exact error message + stack trace/logs
  • Branch immediately:
    • threading/crash → focus on context confinement + NSManagedObjectID handoff
    • migration error → identify model versions + migration strategy
    • batch ops not updating UI → persistent history tracking + merge pipeline

Routing map (pick the right reference fast)

  • Stack setup / merge policies / contexts → references/stack-setup.md
  • Saving patterns → references/saving.md
  • Fetch requests / list updates / aggregates → references/fetch-requests.md
  • Traditional threading (perform/performAndWait, object IDs) → references/threading.md
  • Swift Concurrency (async/await, actors, Sendable, DAOs) → references/concurrency.md
  • Batch insert/delete/update → references/batch-operations.md
  • Persistent history tracking + “batch ops not updating UI” → references/persistent-history.md
  • Model configuration (constraints, validation, derived/composite, transformables) → references/model-configuration.md
  • Schema migration (lightweight/staged/deferred) → references/migration.md
  • CloudKit integration & debugging → references/cloudkit-integration.md
  • Performance profiling & memory → references/performance.md
  • Testing patterns → references/testing.md
  • Terminology → references/glossary.md

Common errors → next best move

  • “Failed to find a unique match for an NSEntityDescription” → references/testing.md (shared NSManagedObjectModel)
  • NSPersistentStoreIncompatibleVersionHashError → references/migration.md (versioning + migration)
  • Cross-context/threading exceptions (e.g. delete/update from wrong context) → references/threading.md and/or references/concurrency.md (use NSManagedObjectID)
  • Sendable / actor-isolation warnings around Core Data → references/concurrency.md (don’t “paper over” with @unchecked Sendable)
  • NSMergeConflict / constraint violations → references/model-configuration.md + references/stack-setup.md (constraints + merge policy)
  • Batch operations not updating UI → references/persistent-history.md + references/batch-operations.md
  • CloudKit schema/sync issues → references/cloudkit-integration.md
  • Memory grows during fetch → references/performance.md + references/fetch-requests.md

Verification checklist (when changing Core Data code)

  • Confirm the context matches the work (UI vs background).
  • Ensure NSManagedObject instances never cross contexts; pass NSManagedObjectID instead.
  • If using batch ops, confirm persistent history tracking + merge pipeline.
  • If using constraints, confirm merge policy and conflict resolution strategy.
  • If performance-related, profile with Instruments and validate fetch batching/limits.

Reference files

  • references/_index.md (navigation)
  • references/stack-setup.md
  • references/saving.md
  • references/fetch-requests.md
  • references/threading.md
  • references/concurrency.md
  • references/batch-operations.md
  • references/persistent-history.md
  • references/model-configuration.md
  • references/migration.md
  • references/cloudkit-integration.md
  • references/performance.md
  • references/testing.md
  • references/glossary.md

来源与署名

来源:avdlee/core-data-agent-skill位于core-data-expert提交855ca7d

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架