affaan-m/ECC

swift-concurrency-6-2

Swift 6.2のアクセシブルな並行処理——デフォルトはシングルスレッド、@concurrentは明示的なバックグラウンドオフロードに使用し、分離の一貫性はMainActor型に使用する。

68Collecting
See how to use itView GitHub source
npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/swift-concurrency-6-2"
Automated source guide

Source checked Jul 28, 2026·Refresh due Oct 26, 2026

Reorganized from the pinned upstream SKILL.md

Turn swift-concurrency-6-2's source instructions into a guide you can follow

According to the pinned SKILL.md from affaan-m/ECC: コードがデフォルトでシングルスレッドで実行され、並行処理が明示的に導入されるSwift 6.2の並行処理モデルを採用したパターン。パフォーマンスを犠牲にすることなく、よくあるデータ競合エラーを排除する。

npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/swift-concurrency-6-2"
Check the pinned source

Best fit

  • Swift 6.2のアクセシブルな並行処理——デフォルトはシングルスレッド、@concurrentは明示的なバックグラウンドオフロードに使用し、分離の一貫性はMainActor型に使用する。

Bring this context

  • A concrete task that matches the documented purpose of swift-concurrency-6-2.
  • The files, examples, or context the task depends on.
  • Your constraints, target environment, and definition of done.

Expected outputs

  • A result that follows the pinned swift-concurrency-6-2 instructions.
  • A concise record of assumptions, inputs used, and unresolved questions.
  • A final check against the source workflow and relevant permission signals.

Key source sections

Read swift-concurrency-6-2 through these 5 source sections

Sections are extracted automatically from the pinned SKILL.md and link back to the source.

01

起動条件

Swift 5.x または 6.0/6.1 プロジェクトを Swift 6.2 に移行する場合 データ競合安全性のコンパイラエラーを解決する場合 MainActorベースのアプリアーキテクチャを設計する場合 CPU集約的な処理をバックグラウンドスレッドにオフロードする場合 MainActor分離された型にプロトコル一貫性を実装する場合 Xcode 26で「アクセシブルな並行処理」ビルド設定を有効にする場合

SKILL.md · 起動条件
Swift 5.x または 6.0/6.1 プロジェクトを Swift 6.2 に移行する場合データ競合安全性のコンパイラエラーを解決する場合MainActorベースのアプリアーキテクチャを設計する場合
02

核心的な問題:暗黙のバックグラウンドオフロード

Swift 6.1以前では、非同期関数が暗黙的にバックグラウンドスレッドにオフロードされ、一見安全に見えるコードでもデータ競合エラーを引き起こすことがあった:

SKILL.md · 核心的な問題:暗黙のバックグラウンドオフロード
Swift 6.1以前では、非同期関数が暗黙的にバックグラウンドスレッドにオフロードされ、一見安全に見えるコードでもデータ競合エラーを引き起こすことがあった:Swift 6.2ではこの問題が修正された:非同期関数はデフォルトで呼び出し元と同じActorに留まる。
03

コアパターン——分離の一貫性

MainActor型が非分離プロトコルに安全に準拠できるようになった:

SKILL.md · コアパターン——分離の一貫性
MainActor型が非分離プロトコルに安全に準拠できるようになった:コンパイラはこの一貫性がMainActor上でのみ使用されることを保証する:
04

コアパターン——グローバル変数と静的変数

MainActorを使用してグローバル/静的状態を保護する:

SKILL.md · コアパターン——グローバル変数と静的変数
MainActorを使用してグローバル/静的状態を保護する:Swift 6.2ではMainActorをデフォルトで推論するパターンが導入された——手動の注釈なし:このパターンはオプトインで、アプリ、スクリプト、その他の実行可能ターゲットに推奨される。
05

MainActorデフォルト推論パターン

Swift 6.2ではMainActorをデフォルトで推論するパターンが導入された——手動の注釈なし:

SKILL.md · MainActorデフォルト推論パターン
Swift 6.2ではMainActorをデフォルトで推論するパターンが導入された——手動の注釈なし:このパターンはオプトインで、アプリ、スクリプト、その他の実行可能ターゲットに推奨される。

SkillSignal prompt templates

Provide the task, context, and acceptance criteria

These prompts were written by SkillSignal from the source structure; they are not upstream text.

Task-start prompt

Confirm source fit, inputs, and outputs before acting.

Use swift-concurrency-6-2 to help me with: [specific task]. Context: [files, data, or background]. Constraints: [environment, scope, and prohibited actions]. Before acting, check the pinned SKILL.md and explain which sections apply, what inputs are still missing, and what you will deliver.

Source-guided execution

Make the Agent explicitly follow the key extracted sections.

Apply the pinned swift-concurrency-6-2 source to [task]. Pay particular attention to these source sections: “起動条件”, “核心的な問題:暗黙のバックグラウンドオフロード”, “コアパターン——分離の一貫性”, “コアパターン——グローバル変数と静的変数”, “MainActorデフォルト推論パターン”. Preserve the important decision at each step. Mark facts not covered by the source as “needs confirmation” instead of inventing them. Then verify the result against my acceptance criteria: [criteria].

Result-review prompt

Check omissions, permissions, and source drift before delivery.

Review the current swift-concurrency-6-2 result: (1) does it satisfy the original task; (2) were any applicable steps or limits in the pinned SKILL.md missed; (3) did it perform any unauthorized file, command, network, or data action; and (4) which conclusions remain unverified? List issues first, then fix only what the source or user authorization supports.

Output checklist

Verify each item before delivery

The task matches the purpose documented in the SKILL.md.

The source section “起動条件” has been checked.

The source section “核心的な問題:暗黙のバックグラウンドオフロード” has been checked.

The source section “コアパターン——分離の一貫性” has been checked.

The source section “コアパターン——グローバル変数と静的変数” has been checked.

Inputs, constraints, and acceptance criteria are explicit.

Unverified facts, compatibility, and outcome claims are clearly marked.

Any file, command, network, or data action has been reviewed.

Choose a different workflow

When another Skill is the better fit

FAQ

What does swift-concurrency-6-2 do?

コードがデフォルトでシングルスレッドで実行され、並行処理が明示的に導入されるSwift 6.2の並行処理モデルを採用したパターン。パフォーマンスを犠牲にすることなく、よくあるデータ競合エラーを排除する。

How do I start using swift-concurrency-6-2?

The catalog detected this source-specific install command: npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/swift-concurrency-6-2". Inspect the command and pinned source before running it.

Which Agent platforms does it declare?

No dedicated Agent platform is declared in the pinned source record.

Repository stars
234,327
Repository forks
35,711
Quality
68/100
Source repository last pushed

Quality breakdown

Based on traceable docs and repository signals; stars are not treated as quality.

68/100
Documentation23/30
Specificity15/25
Maintenance18/20
Trust signals12/25

Compare before choosing

Related Agent Skills and source variants

These links are selected from shared tasks, functions, stacks, platforms, and same-name variants. Compare the source owner, documentation, permissions, and maintenance signals.

swift-concurrency-6-2 by affaan-m

Swift 6.2 Approachable Concurrency — single-threaded by default, @concurrent for explicit background offloading, isolated conformances for main actor types.

swift-concurrency-6-2 by affaan-m

Swift 6.2 可接近的并发性 — 默认单线程,@concurrent 用于显式后台卸载,隔离一致性用于主 actor 类型。

ab-testing by coreyhaines31

When the user wants to plan, design, or implement an A/B test or experiment, or build a growth experimentation program. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "should I test this," "which version is better," "test two versions," "statistical significance," "how long should I run this test," "growth experiments," "experiment velocity," "experiment backlog," "ICE score," "experimentation program

churn-prevention by coreyhaines31

When the user wants to reduce churn, build cancellation flows, set up save offers, recover failed payments, or implement retention strategies. Also use when the user mentions 'churn,' 'cancel flow,' 'offboarding,' 'save offer,' 'dunning,' 'failed payment recovery,' 'win-back,' 'retention,' 'exit survey,' 'pause subscription,' 'involuntary churn,' 'people keep canceling,' 'churn rate is too high,' 'how do I keep users,' or 'customers are leaving.' Use this whenever someone is losing subscribers o

design-intelligence by event4u-app

Grounded design brief from the adopted corpus — style, WCAG-checked color tokens, typography, layout pattern, anti-patterns. Use on ui-design-brief or any which-style/palette/font/chart decision.

View original Skill.mdThis page is parsed directly from the repository SKILL.md without editorial rewriting. Collected: Jul 28, 2026 · about 1 min

Swift 6.2 アクセシブルな並行処理

コードがデフォルトでシングルスレッドで実行され、並行処理が明示的に導入されるSwift 6.2の並行処理モデルを採用したパターン。パフォーマンスを犠牲にすることなく、よくあるデータ競合エラーを排除する。

起動条件

  • Swift 5.x または 6.0/6.1 プロジェクトを Swift 6.2 に移行する場合
  • データ競合安全性のコンパイラエラーを解決する場合
  • MainActorベースのアプリアーキテクチャを設計する場合
  • CPU集約的な処理をバックグラウンドスレッドにオフロードする場合
  • MainActor分離された型にプロトコル一貫性を実装する場合
  • Xcode 26で「アクセシブルな並行処理」ビルド設定を有効にする場合

核心的な問題:暗黙のバックグラウンドオフロード

Swift 6.1以前では、非同期関数が暗黙的にバックグラウンドスレッドにオフロードされ、一見安全に見えるコードでもデータ競合エラーを引き起こすことがあった:

// Swift 6.1: ERROR
@MainActor
final class StickerModel {
    let photoProcessor = PhotoProcessor()

    func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {
        guard let data = try await item.loadTransferable(type: Data.self) else { return nil }

        // Error: Sending 'self.photoProcessor' risks causing data races
        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)
    }
}

Swift 6.2ではこの問題が修正された:非同期関数はデフォルトで呼び出し元と同じActorに留まる。

// Swift 6.2: OK — async stays on MainActor, no data race
@MainActor
final class StickerModel {
    let photoProcessor = PhotoProcessor()

    func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {
        guard let data = try await item.loadTransferable(type: Data.self) else { return nil }
        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)
    }
}

コアパターン——分離の一貫性

MainActor型が非分離プロトコルに安全に準拠できるようになった:

protocol Exportable {
    func export()
}

// Swift 6.1: ERROR — crosses into main actor-isolated code
// Swift 6.2: OK with isolated conformance
extension StickerModel: @MainActor Exportable {
    func export() {
        photoProcessor.exportAsPNG()
    }
}

コンパイラはこの一貫性がMainActor上でのみ使用されることを保証する:

// OK — ImageExporter is also @MainActor
@MainActor
struct ImageExporter {
    var items: [any Exportable]

    mutating func add(_ item: StickerModel) {
        items.append(item)  // Safe: same actor isolation
    }
}

// ERROR — nonisolated context can't use MainActor conformance
nonisolated struct ImageExporter {
    var items: [any Exportable]

    mutating func add(_ item: StickerModel) {
        items.append(item)  // Error: Main actor-isolated conformance cannot be used here
    }
}

コアパターン——グローバル変数と静的変数

MainActorを使用してグローバル/静的状態を保護する:

// Swift 6.1: ERROR — non-Sendable type may have shared mutable state
final class StickerLibrary {
    static let shared: StickerLibrary = .init()  // Error
}

// Fix: Annotate with @MainActor
@MainActor
final class StickerLibrary {
    static let shared: StickerLibrary = .init()  // OK
}

MainActorデフォルト推論パターン

Swift 6.2ではMainActorをデフォルトで推論するパターンが導入された——手動の注釈なし:

// With MainActor default inference enabled:
final class StickerLibrary {
    static let shared: StickerLibrary = .init()  // Implicitly @MainActor
}

final class StickerModel {
    let photoProcessor: PhotoProcessor
    var selection: [PhotosPickerItem]  // Implicitly @MainActor
}

extension StickerModel: Exportable {  // Implicitly @MainActor conformance
    func export() {
        photoProcessor.exportAsPNG()
    }
}

このパターンはオプトインで、アプリ、スクリプト、その他の実行可能ターゲットに推奨される。

コアパターン——@concurrent を使ったバックグラウンド処理

真の並列処理が必要な場合、@concurrent を使って明示的にオフロードする:

重要: この例は「アクセシブルな並行処理」ビルド設定——SE-0466 (MainActorデフォルト分離) と SE-0461 (デフォルト非分離非送信) の有効化が必要。これらの設定を有効にすると、extractSticker は呼び出し元のActorに留まり、可変状態へのアクセスが安全になる。これらの設定なしでは、このコードにはデータ競合がある——コンパイラがフラグを立てる。

nonisolated final class PhotoProcessor {
    private var cachedStickers: [String: Sticker] = [:]

    func extractSticker(data: Data, with id: String) async -> Sticker {
        if let sticker = cachedStickers[id] {
            return sticker
        }

        let sticker = await Self.extractSubject(from: data)
        cachedStickers[id] = sticker
        return sticker
    }

    // Offload expensive work to concurrent thread pool
    @concurrent
    static func extractSubject(from data: Data) async -> Sticker { /* ... */ }
}

// Callers must await
let processor = PhotoProcessor()
processedPhotos[item.id] = await processor.extractSticker(data: data, with: item.id)

@concurrent を使用するには:

  1. コンテナとなる型に nonisolated をマークする
  2. 関数に @concurrent を追加する
  3. 関数がまだ非同期でない場合は async を追加する
  4. 呼び出し側に await を追加する

重要な設計上の決定

決定理由
デフォルトシングルスレッド最も自然なコードはデータ競合がない。並行処理はオプトイン
非同期関数は呼び出し元のActorに留まるデータ競合エラーを引き起こす暗黙のオフロードを排除
分離の一貫性MainActor型が安全でない回避策なしにプロトコルに準拠できる
@concurrent による明示的なオプトインバックグラウンド実行は偶発的なものではなく意図的なパフォーマンス選択
MainActorデフォルト推論アプリターゲットの定型的な @MainActor 注釈を削減
オプトイン採用非破壊的な移行パス——機能を段階的に有効化

移行手順

  1. Xcodeで有効化:ビルド設定のSwift Compiler > Concurrencyセクション
  2. SPMで有効化:パッケージマニフェストで SwiftSettings APIを使用
  3. 移行ツールを使用:swift.org/migrationを通じて自動コード変更
  4. MainActorデフォルトから始める:アプリターゲットの推論モードを有効化
  5. 必要な場所に @concurrent を追加:まずプロファイリングし、ホットパスをオフロード
  6. 徹底的にテスト:データ競合の問題はコンパイル時エラーになる

ベストプラクティス

  • MainActorから始める —— まずシングルスレッドコードを書き、後で最適化する
  • CPU集約的な処理のみに @concurrent を使用する —— 画像処理、圧縮、複雑な計算
  • 主にシングルスレッドのアプリターゲットのMainActor推論モードを有効にする
  • オフロード前にプロファイリングする —— Instrumentsで実際のボトルネックを見つける
  • グローバル変数を保護するために MainActor を使用する —— グローバル/静的な可変状態にはActor分離が必要
  • nonisolated 回避策や @Sendable ラッパーではなく分離の一貫性を使用する
  • 段階的に移行する —— ビルド設定で一度に1つの機能を有効化する

避けるべきアンチパターン

  • すべての非同期関数に @concurrent を適用する(ほとんどはバックグラウンド実行を必要としない)
  • 分離を理解せずにコンパイラエラーを抑制するために nonisolated を使用する
  • Actorが同じ安全性を提供できる場面でレガシーの DispatchQueue パターンを保持する
  • 並行処理関連のFoundation Modelsコードで model.availability チェックをスキップする
  • コンパイラと戦う——データ競合をレポートしている場合、コードには本当の並行処理の問題がある
  • すべての非同期コードがバックグラウンドで実行されると仮定する(Swift 6.2のデフォルト:呼び出し元のActorに留まる)

使用場面

  • すべての新しいSwift 6.2+プロジェクト(「アクセシブルな並行処理」は推奨されるデフォルト設定)
  • Swift 5.x または 6.0/6.1 の並行処理から既存のアプリを移行する場合
  • Xcode 26の採用中にデータ競合安全性のコンパイラエラーを解決する場合
  • MainActorを中心としたアプリアーキテクチャを構築する場合(ほとんどのUIアプリ)
  • パフォーマンス最適化——特定の重い計算をバックグラウンドにオフロードする場合
Source repo
affaan-m/ECC
Skill path
docs/ja-JP/skills/swift-concurrency-6-2/SKILL.md
Commit SHA
4e973d3eaf92
Repository license
MIT
Data collected