swift-actor-persistence
Thread-safe data persistence in Swift using actors — in-memory cache with file-backed storage, eliminating data races by design.
npx skills add mturac/everything-openai-codex --skill swift-actor-persistence --agent codex
Same command for any agent — swap --agent for claude-code, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# 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. ```swift 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 public func save(_ item: T) throws { cache[item.id] = item try persistToFile() } public func delete(_ id: String) throws { cache[id] = nil try persistToFile()
- When to Activate
- Core Pattern
- Actor-Based Repository
- Usage
- Combining with @Observable ViewModel
- Key Design Decisions
- Best Practices
- Anti-Patterns to Avoid
- When to Use
What does the swift-actor-persistence skill do?
Thread-safe data persistence in Swift using actors — in-memory cache with file-backed storage, eliminating data races by design.
How do I install it?
Run `npx skills add mturac/everything-openai-codex --skill swift-actor-persistence --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From mturac/everything-openai-codex, a repository with 84 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
