SKILL

swift-actor-persistence

Swiftでactorを使用してスレッドセーフなデータ永続化を実装する——メモリキャッシュとファイルバックドストレージを組み合わせ、設計によってデータ競合を排除する。

Original · translation did not pass checks

Target: Target not categorized. Automatically collected · unverified.

Excerpt from the author’s documentation

Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.

Read the original Japanese text

Topics in the source

  • スレッドセーフな永続化のための Swift Actor
  • 起動条件
  • コアパターン
  • Actorベースのリポジトリ
  • 使い方
  • @Observable ViewModel との組み合わせ
  • 重要な設計上の決定
  • ベストプラクティス

Swiftのactorを使用してスレッドセーフなデータ永続化レイヤーを構築するパターン。メモリキャッシュとファイルバックドストレージを組み合わせ、actorモデルを活用してコンパイル時にデータ競合を排除する。 Swift 5.5以降でデータ永続化レイヤーを構築する場合 共有可変状態へのスレッドセーフアクセスが必要な場合 手動の同期(ロック、DispatchQueue)を排除したい場合 ローカルストレージを持つオフラインファースとアプリを構築する場合 Actorモデルはシリアライズされたアクセスを保証する——コンパイラによって強制されるデータ競合なし。 Actorの分離により、すべての呼び出しは自動的に非同期になる: | 決定 | 理由 | |----------|-----------| | Actorを使用(クラス + ロックではなく) | コンパイラによって強制されるスレッド安全性、手動同期不要 | | メモリキャッシュ + ファイル永続化 | キャッシュからの高速読み取り、ディスクへの永続的な書き込み | | 初期化時の同期ロード | 非同期初期化の複雑さを回避 | | IDをキーとする辞書 | 識別子によるO(1)検索 | | ジェネリック Codable & Identifiable | あらゆるモデル型で再利用可能 | | アトミックなファイル書き込み(.atomic) | クラッシュ時の部分書き込みを防ぐ | Actorの境界を越えるすべてのデータに Sendable 型を使用する Actorのパブリックなアビリティを最小化する —— 永続化の詳細ではなく、ドメイン操作のみを公開する .atomic 書き込みを使用する —— 書き込み中のアプリクラッシュによるデータ破損を防ぐ init で同期的にロードする —— 非同期イニシャライザはローカルファイルに対するわずかな利点のために複雑さが増す @Observable ViewModelと組み合わせる —— リアクティブなUI更新を実現する Swiftの新しい並行処理コードでActorの代わりに DispatchQueue または NSLock を使用する 内部のキャッシュ辞書を外部の呼び出し元に公開する 初期化後にファイルURLを外部から変更可能にする(初期化時のみ設定を許可すること) すべてのActor メソッド呼び出しが await であることを忘れる——呼び出し元は非同期コンテキストを処理する必要がある Actor の分離をバイパスするために nonisolated を使用する(本末転倒) iOS/macOSアプリのローカルデータストレージ(ユーザーデータ、設定、キャッシュコンテンツ) 後でサーバーと同期するオフラインファーストアーキテクチャ アプリの複数の部分から並行アクセスされる共有可

This is an excerpt. Refer to the complete source and its current requirements.

Source repository
affaan-m/ECC
Source file
docs/ja-JP/skills/swift-actor-persistence/SKILL.md
Fixed revision
d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Read the complete original documentation ↗

Requirements

  • Only the author’s Skill metadata is included. Read the full instructions to check dependencies, licensing and conditions of use.

A small first task

先阅读原作者说明,再决定是否在自己的 AI 工具中使用。

Instructions for your AI tool

Author documentation is not live verification by this site. Without evidence, we do not mark a resource as compatible, safe or free.

Sources and evidence

This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.

Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T14:01:49.739Z.

Categories are inferred from names, descriptions and paths. They do not establish compatibility.

License and attribution

MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.

Original license ↗

Synchronization, copying and user-reported success do not mark a resource as runtime-tested.

Limitations and notes

  • Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.