Swift Concurrency 6 2

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

2,037 stars 332 forksMobile Development Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add xu-xiang/everything-claude-code-zh

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add xu-xiang/everything-claude-code-zh --skill swift-concurrency-6-2
Manual install
git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p ~/.claude/skills
cp -r /tmp/everything-claude-code-zh/skills/swift-concurrency-6-2 ~/.claude/skills/swift-concurrency-6-2

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# 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` 类型现在可以安全地遵守非隔离协议:
Read the full skill on GitHub

Details

Skill name
swift-concurrency-6-2
Path
skills/swift-concurrency-6-2/SKILL.md
License
MIT
Repo updated
5 March 2026

FAQ

What does the Swift Concurrency 6 2 skill do?

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

How do I install the Swift Concurrency 6 2 skill?

Claude Code plugin: /plugin marketplace add xu-xiang/everything-claude-code-zh. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Swift Concurrency 6 2 popular?

It lives in xu-xiang/everything-claude-code-zh, which has 2,037 GitHub stars and 332 forks.

Related skills

Browse the most popular Claude skills, all mobile development skills, or write your own with the skills generator.