Skip to content
affaan-m avatar

Swift Actor Persistence

Thread-safe Swift persistence built on actors, pairing an in-memory cache with atomic file-backed storage.

CCM score
73 of 100
skills.sh installs
12K
GitHub stars
312.6K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers an actor-based repository that serializes all reads and writes, with the compiler enforcing data-race safety
  • Includes a generic LocalRepository over Codable & Identifiable types, plus an @Observable ViewModel integration example
  • Enforces atomic file writes (.atomic) to prevent partial writes on crash, and warns against nonisolated bypasses
  • Designed for offline-first iOS and macOS apps that replace legacy DispatchQueue or NSLock synchronization

Install

$ npx -y skills add affaan-m/ecc --skill swift-actor-persistence -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Swift Actors for Thread-Safe Persistence

Patterns for building thread-safe data persistence layers using Swift actors. Combines in-memory caching with file-backed storage, leveraging the actor model to eliminate data races at compile time.

When to Activate

  • Building a data persistence layer in Swift 5.5+
  • Need thread-safe access to shared mutable state
  • Want to eliminate manual synchronization (locks, DispatchQueues)
  • Building offline-first apps with local storage

Core Pattern

Actor-Based Repository

The actor model guarantees serialized access — no data races, enforced by the compiler.

public actor LocalRepository<T: Codable & Identifiable> where T.ID == String {
    private var cache: [String: T] = [:]
    private let fileURL: URL

    public init(directory: URL = .documentsDirectory, filename: String = "data.json") {
        self.fileURL = directory.appendingPathComponent(filename)
        // Synchronous load during init (actor isolation not yet active)
        self.cache = Self.loadSynchronously(from: fileURL)
    }

    // MARK: - Public API

Details

Repository
github.com/affaan-m/ecc
Categories
Mobile Apps, Databases
First seen
Jul 14, 2026

Questions

What does the swift-actor-persistence skill do?

It guides building a thread-safe data persistence layer in Swift using actors, with an in-memory cache backed by file storage. The actor model keeps shared mutable state free of data races by design.

How do I install the swift-actor-persistence skill?

Run npx -y skills add affaan-m/ecc --skill swift-actor-persistence -y in your project. Once installed, the agent can design actor-based repositories with atomic file writes for local Swift storage.

When should I use swift-actor-persistence instead of locks or DispatchQueues?

Use it when persisting data in Swift 5.5 or later and you want to design out data races instead of managing locks. It suits local storage in iOS or macOS apps and offline-first architectures that sync to a server later.

Which Mobile Apps skills lead the category alongside swift-actor-persistence?

Other skills in the Mobile Apps category include vercel-react-native-skills, animate-expo, write-swift, firebase-crashlytics and xcode-project-setup. swift-actor-persistence focuses specifically on thread-safe Swift persistence with actors.

More from affaan-m/ecc

All 257

Similar to Swift Actor Persistence

More Mobile Apps