swift-actor-persistence

Solid

Use when building a thread-safe data persistence layer in Swift using actors with in-memory cache and file storage.

Data & Documents 183 stars 39 forks Updated 1 months ago MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
75
Recency 20%
75
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Swift Actors for Thread-Safe Persistence # スレッドセーフな永続化のためのSwift Actor **Extracted / 抽出日:** 2026-02-05 **Context / コンテキスト:** iOS/Swift apps requiring thread-safe data persistence with async/await async/awaitを使用したスレッドセーフなデータ永続化が必要なiOS/Swiftアプリ --- ## Problem / 課題 Data persistence layers often face race conditions when multiple parts of an app read/write simultaneously. Traditional approaches (DispatchQueues, locks) are error-prone and verbose. データ永続化レイヤーは、アプリの複数の部分が同時に読み書きする際にレースコンディションに直面することが多い。従来のアプローチ(DispatchQueues、ロック)はエラーが発生しやすく、冗長になりがち。 --- ## Solution / 解決策 Use Swift actors to isolate all persistence state and operations. The actor model guarantees: - No data races (compiler-enforced) - Automatic serialization of access - Async-first API that integrates with structured concurrency Swift actorを使用して、すべての永続化状態と操作を分離する。actorモデルは以下を保証: - データ競合なし(コンパイラによる強制) - アクセスの自動シリアライズ - 構造化並行性と統合されたasyncファーストAPI ```swift public actor LocalRepository { private var cache: [String: Record] = [:] private let cacheFileURL: URL public init(directory: URL = .documentsDirectory) { self.cacheFileURL = directory.appendingPathComponent("cache.json") // Synchronous cache load during init (actor isolation not yet active) // init中の同期キャッシュ読み込み(actor分離がまだアクティブでないため) self.cache = Self.loadCacheSynchronously(from: cacheFileURL) } public func save(_ record: Record) throws { cache[record.id] = record try persistToFile() ...

Details

Author
majiayu000
Repository
majiayu000/claude-skill-registry
Created
5 months ago
Last Updated
1 months ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category