agentsclimarketplace

Ios persistence

Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/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)From its SKILL.md

Install
npx -y skills add ComeOnOliver/skillshub --skill ios-persistence

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

1.8 KB, 358 tokens by cl100k_base, as published. Nobody here has run it

iOS Persistence Standards

Priority: P0

Implementation Guidelines

SwiftData (Current iOS 17+)

  • Models: Use the @Model macro for your Swift classes.
  • Container: Use @MainActor for configuring the ModelContainer.
  • UI State: Use @Query for reactive data fetching in SwiftUI views.
  • Context API: Access modelContext from the @Environment for CRUD (modelContext.insert, modelContext.delete, modelContext.save).

Core Data (Stable & Large Legacy)

  • Mapping: Define your entities and attributes in the .xcdatamodeld file.
  • Stack: Use NSPersistentContainer to encapsulate the SQLite store.
  • Background: Perform heavy writes on newBackgroundContext() to avoid UI lag.
  • Main Context: Use viewContext only for UI thread operations.

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 Documents directory using 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).

References

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.