swift-actor-persistence

Persist Codable Swift data with actor-isolated JSON file storage.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/xxih/ai-harness-zh --skill swift-actor-persistence-xxih
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-actor-persistence
Source: https://github.com/xxih/ai-harness-zh/tree/main/references/translations/everything-claude-code/docs/zh-CN/skills/swift-actor-persistence
Command: npx skills add https://github.com/xxih/ai-harness-zh --skill swift-actor-persistence-xxih

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Swift applications often contend with safely sharing mutable state and ensuring durable data persistence across launches. This Skill demonstrates a pattern that uses Swift actors to enforce thread-safety while maintaining a fast in-memory cache with file-based storage on disk.

Core Features & Use Cases

  • Actor-based persistence layer: isolates state access to a serialized executor, eliminating data races.
  • In-memory cache with durable storage: fast reads with reliable on-disk persistence using JSON.
  • Generic, codable models: stores any model that conforms to Codable and Identifiable.
  • Thread-safe API: public async methods to save, delete, find, and loadAll.

Quick Start

Create a LocalRepository for your Codable models and start saving, loading, and persisting items using actor-isolated methods.

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 data persistence in Swift?

Thread-safe local data persistence in Swift is achieved by using actor isolation to serialize state access, combining an in-memory cache with atomic JSON file writes to prevent data races across concurrent tasks.

How does an actor-based repository handle concurrent file writes?

An actor-based repository handles concurrent file writes by routing all save, delete, and find operations through a serialized executor, ensuring state mutations are isolated and preventing race conditions during disk persistence.

Do I need Swift 5.5 or higher to use actor-based persistence?

Yes, actor-based persistence requires Swift 5.5 or higher because it relies on the actor concurrency model and async APIs to enforce thread-safe state isolation for your Codable and Identifiable models.

What is the best way to cache Codable models locally for offline-first Swift apps?

The best way to cache Codable models locally for offline-first Swift apps is using a generic LocalRepository that maintains fast in-memory reads and automatically persists changes to a durable JSON file on disk.

Can I use this actor-based persistence pattern for storing user settings?

Yes, you can use this actor-based persistence pattern for storing user settings, cached content, or user data, as it safely manages concurrent read and write operations through async public APIs.

Why does my Swift app experience data races when saving to a local file?

Data races occur when multiple concurrent tasks access the same mutable state without synchronization; using Swift actors isolates repository state and serializes file writes to resolve this concurrency issue.