Agent-skills-standard ios-persistence

Implement local persistence with SwiftData, Core Data, and Keychain. Use when setting up SwiftData models, Core Data stacks, or local persistence in iOS. (triggers: **/*.xcdatamodeld, **/*Model.swift, PersistentContainer, FetchRequest, ManagedObject, Query, ModelContainer, Repository)

install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/ios/ios-persistence" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-ios-persistence && rm -rf "$T"
manifest: skills/ios/ios-persistence/SKILL.md
source content

iOS Persistence

Priority: P0

Implementation Workflow

  1. Choose storage tier — SwiftData for iOS 17+, Core Data for legacy, Keychain for secrets, UserDefaults for flags only.
  2. Define models — Use
    @Model
    macro (SwiftData) or
    .xcdatamodeld
    (Core Data).
  3. Configure container — Use
    @MainActor
    for
    ModelContainer
    (SwiftData) or
    NSPersistentContainer
    (Core Data).
  4. Perform background writes — Use
    newBackgroundContext()
    (Core Data) to avoid UI lag; never heavy I/O on
    viewContext
    .
  5. Secure sensitive data — Use Keychain for tokens and PII; never store in
    UserDefaults
    .

See SwiftData and Core Data implementation examples

Anti-Patterns

  • No Heavy I/O on
    viewContext
    : Use private background contexts
  • No String-based Predicates: Use KeyPaths or generated helpers
  • No Missing Merge Strategy: Set
    mergePolicy
    explicitly (e.g.,
    mergeByPropertyObjectTrump
    )

References