swift-actor-persistence

Implements thread-safe Swift persistence using actors with in-memory caching and file-backed storage.

2|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/adamreger/ecc-antigravity --skill swift-actor-persistence-adamreger
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: swift-actor-persistence
Source: https://github.com/adamreger/ecc-antigravity/tree/main/skills/swift-actor-persistence
Command: npx skills add https://github.com/adamreger/ecc-antigravity --skill swift-actor-persistence-adamreger

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Shared mutable state in Swift apps is prone to data races when accessed concurrently, and manual synchronization with locks or DispatchQueues is error-prone. This Skill provides a reusable actor-based repository pattern that guarantees serialized access at compile time while combining fast in-memory reads with durable file-backed storage. ## Core Features & Use Cases - Generic Actor Repository: A LocalRepository<T: Codable & Identifiable> actor providing save, delete, find, and loadAll operations with O(1) dictionary lookups. - Atomic File Persistence: JSON-encoded writes using .atomic options to prevent data corruption on crashes, with synchronous loading during initialization. - SwiftUI Integration: Patterns for combining the repository with @Observable ViewModels for reactive UI updates. - Use Case: Building an offline-first iOS app that caches user data locally — the actor handles all concurrent access safely while persisting changes to disk automatically. ## Quick Start Ask the AI to create a thread-safe Swift actor repository for persisting Codable models to a local JSON file with an in-memory cache.

Frequently Asked Questions about swift-actor-persistence

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

FAQPage Schema
How do I make thread-safe data persistence in Swift?▼

Use a Swift actor as a repository that serializes all access to shared state, enforced by the compiler. Combine an in-memory dictionary cache for fast reads with atomic JSON file writes for durable storage.

How to replace DispatchQueue locks with Swift actors?▼

Wrap the shared mutable state inside an actor instead of guarding it with DispatchQueue or NSLock. All actor method calls become async with await, and the compiler eliminates data races without manual synchronization.

Does Swift actor persistence work with SwiftUI Observable ViewModels?▼

Yes, an @Observable ViewModel can hold a reference to the actor repository and call its async methods with await. After each mutation, reload the published state from the repository to update the UI reactively.

What Swift version is required for actor-based persistence?▼

Swift 5.5 or later is required because actors are part of the Swift concurrency model introduced in that version. The pattern also relies on Codable and Identifiable protocols for generic model support.

When should I not use an actor for local storage?▼

Avoid actors when you need synchronous access from non-async contexts, or when using nonisolated to bypass isolation defeats the safety purpose. For large datasets or complex queries, a database like Core Data or SQLite fits better than file-backed JSON.