swift-actor-persistence

Persist Codable and Identifiable Swift models with actor-based thread-safe storage.

2|Updated Apr 5, 2026
One-click install
npx skills add https://github.com/mbadoz/mbadoz-skills --skill swift-actor-persistence-mbadoz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-actor-persistence
Source: https://github.com/mbadoz/mbadoz-skills/tree/main/plugins/built-planner/skills/built-planner/references/skills/swift-actor-persistence
Command: npx skills add https://github.com/mbadoz/mbadoz-skills --skill swift-actor-persistence-mbadoz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Thread-safe data persistence for Swift apps by combining in-memory caching with file-backed storage to prevent data races and improve performance.

Core Features & Use Cases

  • Actor-based LocalRepository provides serialized access to shared state without manual synchronization.
  • In-memory cache + file persistence enables offline-first behavior and fast reads.
  • Generic over Codable & Identifiable supports common domain models.

Quick Start

Create a LocalRepository<MyModel> and perform save, loadAll, and delete operations to persist and retrieve data.

Frequently Asked Questions about swift-actor-persistence

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

FAQPage Schema
How do I achieve thread-safe data persistence in Swift without manual synchronization?

Thread-safe data persistence in Swift is achieved using an actor-based LocalRepository that serializes access to shared state. It combines an in-memory cache with JSON file-backed storage to prevent data races during concurrent access.

What is the best way to cache Codable models locally in iOS apps?

The best way to cache Codable models locally is using a generic LocalRepository. It provides an in-memory cache for fast reads and durable file persistence via atomic writes, working seamlessly with any Codable and Identifiable domain models.

How do I implement an offline-first local repository for macOS apps?

Implement an offline-first local repository by combining in-memory caching with file-backed storage. An actor-based design ensures safe concurrent access to the persisted Codable data during read and write operations.

Can I use Swift actors for file persistence with concurrent read and write operations?

Yes, Swift actors are designed for file persistence with concurrent read and write operations. The actor LocalRepository isolates shared mutable state, ensuring safe access to the in-memory cache and underlying JSON file storage.

Does this Swift persistence approach require specific model protocols?

This Swift persistence approach requires models to conform to the Codable and Identifiable protocols. These standard Swift protocols allow the generic LocalRepository to serialize data and enforce unique identification for CRUD operations.