swift-actor-persistence

Persist Swift Codable models with actor-isolated in-memory caching and atomic file writes.

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/Oruga420/claude-code-skills --skill swift-actor-persistence-oruga420
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-actor-persistence
Source: https://github.com/Oruga420/claude-code-skills/tree/main/swift-actor-persistence
Command: npx skills add https://github.com/Oruga420/claude-code-skills --skill swift-actor-persistence-oruga420

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The actor-based repository pattern prevents data races and simplifies concurrent access to shared mutable state in Swift applications by combining an in-memory cache with atomic file-backed persistence.

Core Features & Use Cases

  • Actor isolation for thread safety: serialized access enforced by the compiler removes the need for manual locks or dispatch queues.
  • In-memory cache with durable persistence: fast O(1) reads from cache and atomic writes to disk for reliable local storage and offline-first scenarios.
  • Generic Codable & Identifiable models: reusable repository across domain types and easy integration with reactive ViewModels.
  • Use case: maintain a local store of app data (e.g., questions, settings, cached content), update from UI via an @Observable ViewModel, and persist changes reliably across app restarts.

Quick Start

Use the swift-actor-persistence skill to instantiate a LocalRepository for your Codable Identifiable model, load all items, and save or delete entries while relying on actor isolation for thread safety.

Frequently Asked Questions about swift-actor-persistence

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement thread-safe local storage in Swift without manual locks?

Actor isolation provides thread-safe persistence by serializing access to shared mutable state, removing the need for manual locks or dispatch queues while ensuring safe concurrent reads and atomic file writes.

How does actor isolation work for concurrent data access in offline-first Swift apps?

Actor isolation serializes access to an in-memory cache combined with file-backed storage, preventing data races during concurrent operations while delivering O(1) lookups and reliable durable persistence for offline-first scenarios.

Can I use Codable and Identifiable models with an actor-based repository?

Yes, actor-based repositories support generic Codable and Identifiable Swift models, enabling reusable local storage across domain types with straightforward integration into reactive ViewModels for UI synchronization.

What's the best way to persist app data across restarts with async await in Swift?

Using an actor-based repository with async await access patterns allows synchronous init loading, O(1) in-memory cache reads, and atomic file writes for reliable persistence across app restarts.

Does Swift actor-based persistence work with @Observable ViewModels for UI synchronization?

Yes, actor repository methods are called via async await from an @Observable ViewModel, allowing UI layers to safely update, save, or delete entries while the actor guarantees serialized access to cache and disk storage.

When should I avoid actor-based repositories for local storage in Swift?

Avoid actor-based repositories if your app requires synchronous disk access in non-isolated contexts, as the async await access pattern required for actor isolation may introduce unwanted latency in highly synchronous execution paths.