> ios-persistence
Standards for SwiftData, Core Data, and Local Storage. Use when implementing SwiftData, Core Data models, or local persistence in iOS. (triggers: **/*.xcdatamodeld, **/*Model.swift, PersistentContainer, FetchRequest, ManagedObject, Query, ModelContainer, Repository)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/ios-persistence?format=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
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)