
Swift Actor Persistence
This is a practical pattern for local data persistence in Swift 5.5+ that uses actors instead of manual locks or DispatchQueues. You get an in-memory dictionary cache backed by JSON file storage, with compile-time guarantees against data races. The generic repository works with any Codable and Identifiable type, giving you O(1) lookups and atomic file writes. It's most useful for offline-first apps or anywhere you need thread-safe access to shared state without the ceremony of traditional synchronization primitives. The synchronous init load is a reasonable tradeoff that avoids async initialization complexity for local files.
- skills.sh installs
- 5K
- GitHub stars
- 229.1K
- last updated
- Jul 14, 2026
Install
$ npx -y skills add affaan-m/everything-claude-code --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/everything-claude-code
- Category
- Mobile Development
More from affaan-m/everything-claude-code
All 256- Swift Protocol Di Testing5K
- Bun Runtime4.9K
- Nextjs Turbopack4.9K
- Plankton Code Quality4.9K
- Swift Concurrency 6 24.9K
- Visa Doc Translate4.9K
- Ai Regression Testing4.8K
- Architecture Decision Records4.8K
- Blueprint4.8K
- Everything Claude Code Conventions4.8K
- Exa Search4.8K
- Kotlin Testing4.8K
- Customs Trade Compliance4.7K
- Data Scraper Agent4.7K
- Documentation Lookup4.7K
- Enterprise Agent Ops4.7K
- Flutter Dart Code Review4.7K
- Inventory Demand Planning4.7K
- Kotlin Ktor Patterns4.7K
- Nanoclaw Repl4.7K
- Pytorch Patterns4.7K
- Ralphinho Rfc Pipeline4.7K
- Carrier Relationship Management4.6K
- Context Budget4.6K