swift-actor-persistence
Installation
SKILL.md
Swift Actor-Based Data Persistence
Thread-safe data storage in Swift using the actor model, which provides compile-time guarantees against data races.
When to Activate
- Building offline-first applications that need thread-safe persistence
- Implementing local caches or data stores in Swift
- Replacing manual synchronization (locks, dispatch queues) with actors
- Integrating persistence with SwiftUI via
@Observableview models
Core Pattern
The pattern centers on an actor generic over Codable & Identifiable types that maintains an in-memory dictionary and persists to disk atomically:
actor DataRepository<T: Codable & Identifiable> where T.ID: Hashable & Codable {
private var items: [T.ID: T] = [:]
private let fileURL: URL