jpskill.com
💬 コミュニケーション コミュニティ 🟡 少し慣れが必要 👤 幅広いユーザー

💬 Swift Concurrency Expert

swift-concurrency-expert

Swift エキスパート相当の知見を提供するSkill。メール・Slack等のやりとりをする人向け。

⏱ 社内アナウンス文 30分 → 3分

📺 まず動画で見る(YouTube)

▶ 【最新版】Claude(クロード)完全解説!20以上の便利機能をこの動画1本で全て解説 ↗

※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。

📜 元の英語説明(参考)

Review and fix Swift concurrency issues such as actor isolation and Sendable violations.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Swift エキスパート相当の知見を提供するSkill。メール・Slack等のやりとりをする人向け。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o swift-concurrency-expert.zip https://jpskill.com/download/495.zip && unzip -o swift-concurrency-expert.zip && rm swift-concurrency-expert.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/495.zip -OutFile "$d\swift-concurrency-expert.zip"; Expand-Archive "$d\swift-concurrency-expert.zip" -DestinationPath $d -Force; ri "$d\swift-concurrency-expert.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して swift-concurrency-expert.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → swift-concurrency-expert フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
4

💬 こう話しかけるだけ — サンプルプロンプト

  • swift-concurrency-expert の使い方を教えて
  • swift-concurrency-expert で何ができるか具体例で見せて
  • swift-concurrency-expert を初めて使う人向けにステップを案内して

これをClaude Code に貼るだけで、このSkillが自動発動します。

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Swift Concurrency Expert

概要

Swift 6.2+ のコードベースにおける Swift Concurrency の問題を、アクター分離、Sendable の安全性、および最新の並行処理パターンを適用し、最小限の動作変更でレビューおよび修正します。

使用場面

  • ユーザーが Swift Concurrency の使用状況のレビューやコンパイラ診断の修正を求めている場合。
  • アクター分離、Sendable@MainActor、または async 移行に関するガイダンスが必要な場合。

ワークフロー

1. 問題のトリアージ

  • 正確なコンパイラ診断と問題のあるシンボルを特定します。
  • プロジェクトの並行処理設定を確認します。Swift 言語バージョン (6.2+)、厳密な並行処理レベル、およびアプローチ可能な並行処理 (デフォルトのアクター分離 / main-actor-by-default) が有効になっているかどうか。
  • 現在のアクターコンテキスト (@MainActoractornonisolated) と、デフォルトのアクター分離モードが有効になっているかどうかを特定します。
  • コードが UI にバインドされているか、メインアクターから離れて実行されることを意図しているかを確認します。

2. 最小限の安全な修正を適用する

既存の動作を維持しつつ、データ競合の安全性を満たす編集を優先します。

一般的な修正:

  • UI にバインドされた型: 型または関連するメンバーに @MainActor をアノテーションします。
  • メインアクター型でのプロトコル準拠: 準拠を分離します (例: extension Foo: @MainActor SomeProtocol)。
  • グローバル/静的状態: @MainActor で保護するか、アクター内に移動します。
  • バックグラウンド作業: 時間のかかる作業を nonisolated 型の @concurrent async 関数に移動するか、actor を使用して可変状態を保護します。
  • Sendable エラー: イミュータブル/値型を優先します。正しい場合にのみ Sendable 準拠を追加します。スレッドセーフティを証明できない限り @unchecked Sendable は避けてください。

3. 修正の検証

  • リビルドし、すべての並行処理診断が解決され、新しい警告が導入されていないことを確認します。
  • テストスイートを実行して回帰がないか確認します。並行処理の変更は、ビルドがクリーンであっても微妙なランタイムの問題を引き起こす可能性があります。
  • 修正によって新しい警告が表示された場合は、それぞれを新しいトリアージとして扱い (ステップ 1 に戻る)、ビルドがクリーンでテストが合格するまで繰り返し解決します。

UI にバインドされた型 — @MainActor の追加

// Before: ViewModel がメインスレッドからアクセスされているが、アクター分離がないためデータ競合の警告
class ViewModel: ObservableObject {
    @Published var title: String = ""
    func load() { title = "Loaded" }
}

// After: 型全体にアノテーションを付けることで、すべての保存された状態とメソッドが
// 自動的にメインアクターに分離される
@MainActor
class ViewModel: ObservableObject {
    @Published var title: String = ""
    func load() { title = "Loaded" }
}

プロトコル準拠の分離

// Before: コンパイラエラー — SomeProtocol メソッドは非分離だが、
// 準拠する型は @MainActor
@MainActor
class Foo: SomeProtocol {
    func protocolMethod() { /* accesses main-actor state */ }
}

// After: 準拠を @MainActor にスコープすることで、要件が
// 正しい分離コンテキスト内で満たされる
@MainActor
extension Foo: SomeProtocol {
    func protocolMethod() { /* safely accesses main-actor state */ }
}

@concurrent を使用したバックグラウンド作業

// Before: 時間のかかる計算がメインアクターをブロックする
@MainActor
func processData(_ input: [Int]) -> [Int] {
    input.map { heavyTransform($0) }   // runs on main thread
}

// After: 時間のかかる作業のためにメインアクターから離れ、結果を返す
// 呼び出し元は結果を待ち、自身のアクターにとどまる
nonisolated func processData(_ input: [Int]) async -> [Int] {
    await Task.detached(priority: .userInitiated) {
        input.map { heavyTransform($0) }
    }.value
}

// または、@concurrent async 関数 (Swift 6.2+) を使用する場合:
@concurrent
func processData(_ input: [Int]) async -> [Int] {
    input.map { heavyTransform($0) }
}

参考資料

  • Swift 6.2 の変更点、パターン、例については references/swift-6-2-concurrency.md を参照してください。
  • プロジェクトがアプローチ可能な並行処理モードを選択している場合は references/approachable-concurrency.md を参照してください。
  • SwiftUI 固有の並行処理ガイダンスについては references/swiftui-concurrency-tour-wwdc.md を参照してください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Swift Concurrency Expert

Overview

Review and fix Swift Concurrency issues in Swift 6.2+ codebases by applying actor isolation, Sendable safety, and modern concurrency patterns with minimal behavior changes.

When to Use

  • When the user asks to review Swift concurrency usage or fix compiler diagnostics.
  • When you need guidance on actor isolation, Sendable, @MainActor, or async migration.

Workflow

1. Triage the issue

  • Capture the exact compiler diagnostics and the offending symbol(s).
  • Check project concurrency settings: Swift language version (6.2+), strict concurrency level, and whether approachable concurrency (default actor isolation / main-actor-by-default) is enabled.
  • Identify the current actor context (@MainActor, actor, nonisolated) and whether a default actor isolation mode is enabled.
  • Confirm whether the code is UI-bound or intended to run off the main actor.

2. Apply the smallest safe fix

Prefer edits that preserve existing behavior while satisfying data-race safety.

Common fixes:

  • UI-bound types: annotate the type or relevant members with @MainActor.
  • Protocol conformance on main actor types: make the conformance isolated (e.g., extension Foo: @MainActor SomeProtocol).
  • Global/static state: protect with @MainActor or move into an actor.
  • Background work: move expensive work into a @concurrent async function on a nonisolated type or use an actor to guard mutable state.
  • Sendable errors: prefer immutable/value types; add Sendable conformance only when correct; avoid @unchecked Sendable unless you can prove thread safety.

3. Verify the fix

  • Rebuild and confirm all concurrency diagnostics are resolved with no new warnings introduced.
  • Run the test suite to check for regressions — concurrency changes can introduce subtle runtime issues even when the build is clean.
  • If the fix surfaces new warnings, treat each one as a fresh triage (return to step 1) and resolve iteratively until the build is clean and tests pass.

Examples

UI-bound type — adding @MainActor

// Before: data-race warning because ViewModel is accessed from the main thread
// but has no actor isolation
class ViewModel: ObservableObject {
    @Published var title: String = ""
    func load() { title = "Loaded" }
}

// After: annotate the whole type so all stored state and methods are
// automatically isolated to the main actor
@MainActor
class ViewModel: ObservableObject {
    @Published var title: String = ""
    func load() { title = "Loaded" }
}

Protocol conformance isolation

// Before: compiler error — SomeProtocol method is nonisolated but the
// conforming type is @MainActor
@MainActor
class Foo: SomeProtocol {
    func protocolMethod() { /* accesses main-actor state */ }
}

// After: scope the conformance to @MainActor so the requirement is
// satisfied inside the correct isolation context
@MainActor
extension Foo: SomeProtocol {
    func protocolMethod() { /* safely accesses main-actor state */ }
}

Background work with @concurrent

// Before: expensive computation blocks the main actor
@MainActor
func processData(_ input: [Int]) -> [Int] {
    input.map { heavyTransform($0) }   // runs on main thread
}

// After: hop off the main actor for the heavy work, then return the result
// The caller awaits the result and stays on its own actor
nonisolated func processData(_ input: [Int]) async -> [Int] {
    await Task.detached(priority: .userInitiated) {
        input.map { heavyTransform($0) }
    }.value
}

// Or, using a @concurrent async function (Swift 6.2+):
@concurrent
func processData(_ input: [Int]) async -> [Int] {
    input.map { heavyTransform($0) }
}

Reference material

  • See references/swift-6-2-concurrency.md for Swift 6.2 changes, patterns, and examples.
  • See references/approachable-concurrency.md when the project is opted into approachable concurrency mode.
  • See references/swiftui-concurrency-tour-wwdc.md for SwiftUI-specific concurrency guidance.

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。