Skillshub 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)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/ios-persistence" ~/.claude/skills/comeonoliver-skillshub-ios-persistence && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/ios-persistence/SKILL.mdsource content
iOS Persistence Standards
Priority: P0
Implementation Guidelines
SwiftData (Current iOS 17+)
- Models: Use the
macro for your Swift classes.@Model - Container: Use
for configuring the@MainActor
.ModelContainer - UI State: Use
for reactive data fetching in SwiftUI views.@Query - Context API: Access
from themodelContext
for CRUD (modelContext.insert, modelContext.delete, modelContext.save).@Environment
Core Data (Stable & Large Legacy)
- Mapping: Define your entities and attributes in the
file..xcdatamodeld - Stack: Use
to encapsulate the SQLite store.NSPersistentContainer - Background: Perform heavy writes on
to avoid UI lag.newBackgroundContext() - Main Context: Use
only for UI thread operations.viewContext
Local Persistence (Small Data)
- Keychain: Use for Auth tokens, passwords, and PII. Never store sensitive keys in
.UserDefaults - UserDefaults: Use for lightweight settings/flags (e.g.,
).isDarkModeEnabled - File System: Save images or PDFs to the
directory usingDocuments
.Data.write(to:)
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).