
Swift Actor Persistence
This gives you a generic actor-based repository pattern for thread-safe local persistence in Swift. It wraps an in-memory dictionary cache with file-backed JSON storage, so reads are fast and writes are durable. The actor isolation means no manual locks or dispatch queues, and the compiler enforces thread safety at build time. You get synchronous loading during init to avoid async initialization hell, atomic file writes to prevent corruption on crashes, and it works with any Codable type that has a string ID. Solid choice for offline-first iOS apps or anywhere you need shared mutable state without the usual concurrency footguns. The ViewModel integration example shows how it composes cleanly with SwiftUI's Observable macro.
- skills.sh installs
- 5.4K
- GitHub stars
- 300.3K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add affaan-m/ecc --skill swift-actor-persistence --agent claude-codeInstalls into .claude/skills of the current project.
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
Sponsors
Details
- Repository
- github.com/affaan-m/ecc
- Categories
- Mobile Development, Design & UI/UX
- First seen
- Jul 14, 2026
More from affaan-m/ecc
All 263- Quarkus Security5.4K
- Social Graph Ranker5.4K
- Network Bgp Diagnostics5.4K
- Visa Doc Translate5.4K
- Flox Environments5.4K
- Unified Notifications Ops5.4K
- Project Flow Ops5.4K
- Social Publisher5.4K
- Hermes Imports5.4K
- Evm Token Decimals5.4K
- Perl Patterns5.4K
- Quarkus Tdd5.4K
- Quarkus Verification5.4K
- Ralphinho Rfc Pipeline5.4K
- Perl Testing5.4K
- Nanoclaw Repl5.4K
- Messages Ops5.4K
- Recsys Pipeline Architect5.4K
- Latency Critical Systems5.3K
- Fsharp Testing5.3K
- Tinystruct Patterns5.3K
- Uncloud5.3K
- Parallel Execution Optimizer5.3K
- Prediction Market Oracle Research5.3K