swift-actor-persistence

Provide thread-safe local persistence for Swift Codable models with actor-based caching.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/KumarAdi8/AgentKit --skill swift-actor-persistence-kumaradi8
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-actor-persistence
Source: https://github.com/KumarAdi8/AgentKit/tree/main/skills/swift-actor-persistence
Command: npx skills add https://github.com/KumarAdi8/AgentKit --skill swift-actor-persistence-kumaradi8

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a simple, compiler-enforced way to eliminate data races and synchronize access to local mutable state in Swift applications by using actor-based repositories instead of manual locks or DispatchQueues. It makes concurrent reads fast via an in-memory cache and ensures durable writes with atomic file persistence, reducing concurrency bugs and crash-corruption risks.

Core Features & Use Cases

  • Actor-based repository pattern for serialized, thread-safe access to shared model data.
  • In-memory caching combined with file-backed persistence for fast reads and durable storage.
  • Generic support for types conforming to Codable and Identifiable, suitable for SPM packages, app extensions, and app groups.
  • Practical for offline-first apps, local repositories without SwiftData, and sharing state with widgets via App Groups.

Quick Start

Instantiate a LocalRepository for your Codable & Identifiable model, then use await repository.save(item) and await repository.loadAll() for thread-safe writes and reads.

Frequently Asked Questions about swift-actor-persistence

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

FAQPage Schema
How do I eliminate data races in Swift local storage?

To eliminate data races in Swift local storage, use an actor-based repository pattern that serializes access to mutable state, replacing manual locks or DispatchQueues with compiler-enforced thread safety.

How do I persist Codable Swift objects across actor boundaries?

Persist Codable Swift objects across actor boundaries by passing Sendable-aware data to an actor repository, which caches models in-memory for fast concurrent reads and writes them durably to a file.

Can I use actor-based persistence for sharing data with widgets via App Groups?

Yes, you can use actor-based persistence for sharing data with widgets via App Groups, as the repository supports file-backed storage that is accessible across iOS, macOS, watchOS apps, and app extensions.

What's the best way to handle thread-safe local repositories without SwiftData?

The best way to handle thread-safe local repositories without SwiftData is using an actor-based pattern with in-memory caching and atomic file writes, ensuring safe concurrent access for offline-first apps.

Does actor-based local persistence work with SPM packages?

Yes, actor-based local persistence works with SPM packages, providing generic support for any types conforming to Codable and Identifiable across your Swift 5.5+ concurrency projects.

Why use actors instead of DispatchQueues for Swift local storage?

Use actors instead of DispatchQueues for Swift local storage to get compiler-enforced synchronization that eliminates data races, combined with in-memory caching and atomic file writes to prevent crash-corruption risks.