Skip to content
Back to skills

Ios Persistence

ASecurity

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)

  • 67 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 10, 2026
ai-agentsswiftsqlreactapi

Works with

  • api

Security analysis

A100/100

Scanned November 10, 2026

npx -y skills add ComeOnOliver/skillshub --skill ios-persistence --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ios Persistence?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ios Persistence
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/comeonoliver-ios-persistence/badge)](https://www.skillsdirectory.com/skills/comeonoliver-ios-persistence)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ios-persistence
description: '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)'
---

# 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

- [SwiftData & Core Data Implementation](references/implementation.md)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.