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.mdsource content
iOS Persistence
Priority: P0
Implementation Workflow
- Choose storage tier — SwiftData for iOS 17+, Core Data for legacy, Keychain for secrets, UserDefaults for flags only.
- Define models — Use
macro (SwiftData) or@Model
(Core Data)..xcdatamodeld - Configure container — Use
for@MainActor
(SwiftData) orModelContainer
(Core Data).NSPersistentContainer - Perform background writes — Use
(Core Data) to avoid UI lag; never heavy I/O onnewBackgroundContext()
.viewContext - 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
: Use private background contextsviewContext - No String-based Predicates: Use KeyPaths or generated helpers
- No Missing Merge Strategy: Set
explicitly (e.g.,mergePolicy
)mergeByPropertyObjectTrump