Agent skill

Swift Concurrency 6 2

by xu-xiang in xu-xiang/everything-claude-code-zh

Swift 6.2 易用的并发(Approachable Concurrency)—— 默认单线程,使用 @concurrent 进行显式后台卸载,针对主执行角色(Main Actor)类型的隔离一致性。

MITAuto-check passedMobile

Install Swift Concurrency 6 2

skills CLI
$ npx skills add xu-xiang/everything-claude-code-zh --skill swift-concurrency-6-2 -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install xu-xiang/everything-claude-code-zh swift-concurrency-6-2 --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/swift-concurrency-6-2 .claude/skills/swift-concurrency-6-2 && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
swift-concurrency-6-2
GitHub stars
2k
Token cost
~1.4k tokens
SKILL.md length
225 words
Files
1
Skills in repo
78
Repo updated
First seen
Licence
MIT

At a glance

Swift 6.2 易用的并发(Approachable Concurrency)—— 默认单线程,使用 @concurrent 进行显式后台卸载,针对主执行角色(Main Actor)类型的隔离一致性。

  • Works in 4 steps: 将包含类型标记为 nonisolated → 为函数添加 @concurrent → 如果尚未异步,则添加 async → …
  • Mobile work in your project
  • SKILL.md covers 何时激活, 核心问题:隐式后台卸载, 核心模式 —— 隔离一致性 (Isolated… and 核心模式 —— 全局和静态变量, plus 6 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Swift Concurrency 6 2 is an agent skill from xu-xiang/everything-claude-code-zh. Swift 6.2 易用的并发(Approachable Concurrency)—— 默认单线程,使用 @concurrent 进行显式后台卸载,针对主执行角色(Main Actor)类型的隔离一致性。

Its SKILL.md is about 1.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile. It works with Swift. The repository describes itself as: everything-claude-code 中文翻译项目:完整的 Claude Code 配置集合(agents, skills, hooks, commands, rules, MCPs)。源自 Anthropic 黑客松获胜者的实战配置,助力中文工程师高效理解与使用 Claude Code。 The licence is MIT.

When your agent uses it

  • Mobile work in your project

Example prompts

  • “/swift-concurrency-6-2”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. 将包含类型标记为 nonisolated
  2. 为函数添加 @concurrent
  3. 如果尚未异步,则添加 async
  4. 在调用处添加 await

What it can do on your machine

Read from SKILL.md and the folder at commit dfbf946. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are swift).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Swift Concurrency 6 2 loads about 1.4k tokens when it runs. Until then it costs about 31 tokens; SKILL.md has 225 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~31
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from xu-xiang/everything-claude-code-zh at commit dfbf946, republished under its MIT licence (© xu-xiang). 225 words, ~1,363 tokens.

Download SKILL.mdSave it as .claude/skills/swift-concurrency-6-2/SKILL.md (or your agent's skills folder).
name
swift-concurrency-6-2
description
Swift 6.2 易用的并发(Approachable Concurrency)—— 默认单线程,使用 @concurrent 进行显式后台卸载,针对主执行角色(Main Actor)类型的隔离一致性。

Swift 6.2 易用的并发 (Approachable Concurrency)

采用 Swift 6.2 并发模型的模式:代码默认在单线程运行,并发需显式引入。在不牺牲性能的情况下消除常见的数据竞争(Data-race)错误。

何时激活

  • 将 Swift 5.x 或 6.0/6.1 项目迁移到 Swift 6.2
  • 解决数据竞争安全的编译器错误
  • 设计基于 MainActor 的应用架构
  • 将 CPU 密集型工作卸载到后台线程
  • 在 MainActor 隔离的类型上实现协议一致性(Protocol conformances)
  • 在 Xcode 26 中启用易用的并发(Approachable Concurrency)构建设置

核心问题:隐式后台卸载

在 Swift 6.1 及更早版本中,异步函数(Async functions)可能会被隐式卸载到后台线程,即使在看似安全的代码中也会导致数据竞争错误:

swift
// 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 }

        // 错误:发送 'self.photoProcessor' 存在引起数据竞争的风险
        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)
    }
}

Swift 6.2 修复了这个问题:异步函数默认保留在调用方执行角色(Actor)上。

swift
// Swift 6.2: 正常 (OK) — 异步保留在 MainActor,无数据竞争
@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)
    }
}

核心模式 —— 隔离一致性 (Isolated Conformances)

MainActor 类型现在可以安全地遵守非隔离协议:

swift
protocol Exportable {
    func export()
}

// Swift 6.1: 错误 (ERROR) — 跨入主执行角色隔离的代码
// Swift 6.2: 正常 (OK),使用隔离一致性
extension StickerModel: @MainActor Exportable {
    func export() {
        photoProcessor.exportAsPNG()
    }
}

编译器确保该一致性仅在主执行角色上使用:

swift
// 正常 (OK) — ImageExporter 也是 @MainActor
@MainActor
struct ImageExporter {
    var items: [any Exportable]

    mutating func add(_ item: StickerModel) {
        items.append(item)  // 安全:相同的执行角色隔离
    }
}

// 错误 (ERROR) — 非隔离上下文不能使用 MainActor 一致性
nonisolated struct ImageExporter {
    var items: [any Exportable]

    mutating func add(_ item: StickerModel) {
        items.append(item)  // 错误:此处无法使用 Main actor 隔离的一致性
    }
}

核心模式 —— 全局和静态变量

使用 MainActor 保护全局/静态状态:

swift
// Swift 6.1: 错误 (ERROR) — 非 Sendable 类型可能具有共享的可变状态
final class StickerLibrary {
    static let shared: StickerLibrary = .init()  // 错误
}

// 修复:添加 @MainActor 注解
@MainActor
final class StickerLibrary {
    static let shared: StickerLibrary = .init()  // 正常 (OK)
}
MainActor 默认推断模式

Swift 6.2 引入了一种默认推断 MainActor 的模式 —— 无需手动注解:

swift
// 启用 MainActor 默认推断后:
final class StickerLibrary {
    static let shared: StickerLibrary = .init()  // 隐式为 @MainActor
}

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

extension StickerModel: Exportable {  // 隐式为 @MainActor 一致性
    func export() {
        photoProcessor.exportAsPNG()
    }
}

此模式为选填项,推荐用于 App、脚本和其他可执行目标。

核心模式 —— 使用 @concurrent 进行后台工作

当你需要真正的并行性时,使用 @concurrent 显式卸载:

重要提示: 此示例需要“易用的并发”构建设置 —— SE-0466(MainActor 默认隔离)和 SE-0461(默认非隔离且非发送)。启用这些设置后,extractSticker 会保留在调用方的执行角色上,从而使可变状态访问变得安全。如果没有这些设置,此代码将存在数据竞争 —— 编译器会对其报错。

swift
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
    }

    // 将高耗时工作卸载到并发线程池
    @concurrent
    static func extractSubject(from data: Data) async -> Sticker { /* ... */ }
}

// 调用方必须使用 await
let processor = PhotoProcessor()
processedPhotos[item.id] = await processor.extractSticker(data: data, with: item.id)

使用 @concurrent 的步骤:

  1. 将包含类型标记为 nonisolated
  2. 为函数添加 @concurrent
  3. 如果尚未异步,则添加 async
  4. 在调用处添加 await

关键设计决策

决策原理
默认单线程大多数自然编写的代码都是无数据竞争的;并发是选填的
异步保留在调用执行角色上消除导致数据竞争错误的隐式卸载
隔离一致性MainActor 类型可以遵守协议,而无需不安全的临时方案
@concurrent 显式选填后台执行是深思熟虑的性能选择,而非偶然
MainActor 默认推断减少 App 目标中冗余的 @MainActor 注解
选填式采用非破坏性的迁移路径 —— 增量启用功能

迁移步骤

  1. 在 Xcode 中启用:构建设置 (Build Settings) 中的 Swift Compiler > Concurrency 部分
  2. 在 SPM 中启用:在包清单中使用 SwiftSettings API
  3. 使用迁移工具:通过 swift.org/migration 进行自动代码更改
  4. 从 MainActor 默认设置开始:为 App 目标启用推断模式
  5. 在需要处添加 @concurrent:先进行性能分析 (Profile),然后卸载热点路径
  6. 彻底测试:数据竞争问题将变为编译时错误

最佳实践

  • 从 MainActor 开始 —— 先编写单线程代码,稍后再进行优化
  • 仅针对 CPU 密集型工作使用 @concurrent —— 图像处理、压缩、复杂计算
  • 为大部分是单线程的 App 目标启用 MainActor 推断模式
  • 在卸载前进行性能分析 —— 使用 Instruments 查找真正的瓶颈
  • 使用 MainActor 保护全局变量 —— 全局/静态可变状态需要执行角色隔离
  • 使用隔离一致性,而不是 nonisolated 临时方案或 @Sendable 包装器
  • 增量迁移 —— 在构建设置中一次启用一个功能

应避免的反模式 (Anti-Patterns)

  • 对每个异步函数都应用 @concurrent(大多数函数不需要后台执行)
  • 在不理解隔离的情况下使用 nonisolated 来压制编译器错误
  • 在执行角色(Actors)提供相同安全性时仍保留旧的 DispatchQueue 模式
  • 在并发相关的 Foundation Models 代码中跳过 model.availability 检查
  • 与编译器对抗 —— 如果它报告数据竞争,说明代码存在真正的并发问题
  • 假设所有异步代码都在后台运行(Swift 6.2 默认:保留在调用执行角色上)

何时使用

  • 所有新的 Swift 6.2+ 项目(推荐默认使用“易用的并发”)
  • 从 Swift 5.x 或 6.0/6.1 并发迁移现有 App
  • 在采用 Xcode 26 期间解决数据竞争安全的编译器错误
  • 构建以 MainActor 为中心的应用架构(大多数 UI App)
  • 性能优化 —— 将特定的繁重计算卸载到后台

© xu-xiang, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/swift-concurrency-6-2 of xu-xiang/everything-claude-code-zh.

Open the folder on GitHubat commit dfbf946

Compare with similar skills

Swift Concurrency 6 2 next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Swift Concurrency 6 2 compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Swift Concurrency 6 2 this skillxu-xiang/everything-claude-code-zh2k—~1.4kAutomated safety check: PassMIT
Swift Concurrency Expertharperreed/dotfiles3345 repos~506Automated safety check: PassNone
Swift Concurrency Expertdavila7/claude-code-templates33k3 repos~1.1kAutomated safety check: PassMIT
Swift Concurrencydpearson2699/swift-ios-skills1.2k—~5kAutomated safety check: PassCustom licence
Swift Concurrency 6 2affaan-m/ECC276k—~1.5kAutomated safety check: PassMIT
Memorygustavscirulis/snapgrid1161 repos~3kAutomated safety check: PassCustom licence

Similar skills

  • Swift Concurrency Expert

    harperreed/dotfiles

    Swift Concurrency review and remediation for Swift 6.2+. An agent skill from harperreed/dotfiles.

    334 GitHub starsUsed in 5 repos~506 tokens
    MobileAuto-check passed
  • Swift Concurrency Expert

    davila7/claude-code-templates

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

    33k GitHub starsUsed in 3 repos~1.1k tokens
    MobileAuto-check passed
  • Swift Concurrency

    dpearson2699/swift-ios-skills

    Resolve Swift concurrency compiler errors, adopt approachable concurrency (SE-0466), and write data-race-safe async code.

    1.2k GitHub stars~5k tokensUpdated 2 mo ago
    MobileAuto-check passed
  • Swift 6.2のアクセシブルな並行処理——デフォルトはシングルスレッド、@concurrentは明示的なバックグラウンドオフロードに使用し、分離の一貫性はMainActor型に使用する。

    276k GitHub stars~1.5k tokensUpdated yesterday
    MobileAuto-check passed
  • Memory

    gustavscirulis/snapgrid

    Swift 6.2 InlineArray and Span types for zero-overhead memory access, fixed-size collections, and safe pointer alternatives.

    116 GitHub starsUsed in 1 repo~3k tokens
    MobileAuto-check passed
  • Swift Concurrency Updates

    gustavscirulis/snapgrid

    Swift 6.2 concurrency updates including default MainActor inference, @concurrent for background work, isolated conformances, and approachable concurrency migration.

    116 GitHub starsUsed in 1 repo~5.1k tokens
    MobileAuto-check passed

More from xu-xiang/everything-claude-code-zh

All 78 skills in this repo
  • Configure Ecc

    xu-xiang/everything-claude-code-zh

    Everything Claude Code 的交互式安装程序 — 引导用户选择并安装技能和规则到用户级或项目级目录,验证路径,并可选择优化已安装文件。

    2k GitHub starsUsed in 1 repo~2.1k tokens
    Auto-check passed
  • Continuous Learning V2

    xu-xiang/everything-claude-code-zh

    基于本能(Instinct)的学习系统,通过钩子(hooks)观察会话,创建带有置信度评分的原子本能,并将其演化为技能(Skills)、命令(Commands)或智能体(Agents)。v2.1 版本增加了项目作用域(project-scoped)的本能,以防止跨项目污染。

    2k GitHub stars~2.1k tokensUpdated 7 mo ago
    Auto-check passed
  • API Design

    xu-xiang/everything-claude-code-zh

    生产级 API 的 REST API 设计模式,包括资源命名、状态码、分页、过滤、错误响应、版本控制和速率限制. An agent skill from xu-xiang/everything-claude-code-zh.

    2k GitHub stars~2.7k tokensUpdated 7 mo ago
    Auto-check passed
  • Backend Patterns

    xu-xiang/everything-claude-code-zh

    后端架构模式、API 设计、数据库优化以及适用于 Node.js、Express 和 Next.js API 路由的服务端最佳实践。

    2k GitHub stars~3.2k tokensUpdated 7 mo ago
    Auto-check passed
  • Backend Patterns

    xu-xiang/everything-claude-code-zh

    后端架构模式、API 设计、数据库优化以及 Node.js、Express 和 Next.js API 路由的服务端最佳实践。

    2k GitHub stars~3.1k tokensUpdated 7 mo ago
    Auto-check passed
  • Backend Patterns

    xu-xiang/everything-claude-code-zh

    后端架构模式、API 设计、数据库优化以及针对 Node.js、Express 和 Next.js API 路由的服务端最佳实践。

    2k GitHub stars~3.2k tokensUpdated 7 mo ago
    Auto-check passed

Works with

Categories

Questions about Swift Concurrency 6 2

What does Swift Concurrency 6 2 do?

Swift 6.2 易用的并发(Approachable Concurrency)—— 默认单线程,使用 @concurrent 进行显式后台卸载,针对主执行角色(Main Actor)类型的隔离一致性。. Swift Concurrency 6 2 is an agent skill from xu-xiang/everything-claude-code-zh.

When should I use Swift Concurrency 6 2?

Swift Concurrency 6 2 fits situations like: mobile work in your project.

How do I install Swift Concurrency 6 2 in Claude Code?

Run `npx skills add xu-xiang/everything-claude-code-zh --skill swift-concurrency-6-2 -a claude-code`. Or copy the skill folder (skills/swift-concurrency-6-2 in xu-xiang/everything-claude-code-zh) into .claude/skills/swift-concurrency-6-2 in your project. Claude Code loads it when a task matches its description.

How do I install Swift Concurrency 6 2 in Codex?

Run `npx skills add xu-xiang/everything-claude-code-zh --skill swift-concurrency-6-2 -a codex`. Or copy the skill folder (skills/swift-concurrency-6-2 in xu-xiang/everything-claude-code-zh) into .agents/skills/swift-concurrency-6-2 in your project. Codex loads it when a task matches its description.

Can I use Swift Concurrency 6 2 in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add xu-xiang/everything-claude-code-zh --skill swift-concurrency-6-2 -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/swift-concurrency-6-2, .gemini/skills/swift-concurrency-6-2, .github/skills/swift-concurrency-6-2 and .opencode/skills/swift-concurrency-6-2 in your project.

What does Swift Concurrency 6 2 need to run?

SKILL.md names no scripts, command-line tools or credentials: Swift Concurrency 6 2 is instructions for the agent only.

Does Swift Concurrency 6 2 access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Swift Concurrency 6 2 safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Swift Concurrency 6 2 use?

Swift Concurrency 6 2 is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Swift Concurrency 6 2 use?

About 1.4k tokens (SKILL.md is roughly 5.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Swift Concurrency 6 2?

Skills that share tags, products or a category with Swift Concurrency 6 2: Swift Concurrency Expert (harperreed/dotfiles, 334 stars), Swift Concurrency Expert (davila7/claude-code-templates, 33k stars), Swift Concurrency (dpearson2699/swift-ios-skills, 1.2k stars) and Swift Concurrency 6 2 (affaan-m/ECC, 276k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Swift Concurrency 6 2?

xu-xiang (a GitHub user) maintains it in xu-xiang/everything-claude-code-zh, which has 1,978 GitHub stars. The repository holds 78 skills in this directory. The repository was last updated on March 5, 2026.

Source: xu-xiang/everything-claude-code-zh on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.