Agent skill
iOS Persistence
Standards for SwiftData, Core Data, and Local Storage.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/persistence
Metadata
Additional technical details for this skill
- labels
-
ios persistence swiftdata coredata sqlite
- triggers
-
{ "files": [ "**/*.xcdatamodeld", "**/*Model.swift" ], "keywords": [ "PersistentContainer", "FetchRequest", "ManagedObject", "Query", "ModelContainer", "Repository" ] }
SKILL.md
iOS Persistence Standards
Priority: P0
Implementation Guidelines
SwiftData (iOS 17+)
- Models: Use
@Modelmacro for pure Swift classes. - Container: Use
ModelContainerfor schema management. Inject into the environment for SwiftUI apps. - Queries: Use
@Queryfor declarative data fetching in Views.
Core Data (Standard)
- Persistent Stack: Initialize
NSPersistentContainerin a dedicatedPersistenceController. - Context Management: Use
viewContextfor UI tasks andnewBackgroundContext()for heavy imports to avoid blocking the main thread. - FetchedResultsController: Use
NSFetchedResultsControllerfor efficient list management with change tracking.
Best Practices
- Migration: Always perform lightweight migrations for minor schema changes. Use versioned models for complex migrations.
- Threading: Managed objects are not thread-safe. Always access them on the context's queue (e.g.,
perform { ... }). - Batching: Use
NSBatchUpdateRequestorNSBatchDeleteRequestfor large datasets.
Anti-Patterns
- Main Thread Blocking:
**No heavy I/O on ViewContext**: Use private background contexts. - Manual String Keys:
**No string-based predicates**: Use KeyPaths or generated helpers. - Missing Merge Policies:
**No merge strategy**: Explicitly set mergePolicy (e.g., mergeByPropertyObjectTrump).
References
- SwiftData & Core Data Implementation
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?