Swift Concurrency 6 2
Swift 6.2 易用的并发(Approachable Concurrency)—— 默认单线程,使用 @concurrent 进行显式后台卸载,针对主执行角色(Main Actor)类型的隔离一致性。
Install
/plugin marketplace add xu-xiang/everything-claude-code-zhThe repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.
npx skills add xu-xiang/everything-claude-code-zh --skill swift-concurrency-6-2git 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-2Personal 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` 类型现在可以安全地遵守非隔离协议:Details
- Skill name
swift-concurrency-6-2- Repository
- xu-xiang/everything-claude-code-zh
- 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
Backend Patterns
2kxu-xiang/everything-claude-code-zh
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Coding Standards
2kxu-xiang/everything-claude-code-zh
Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.
Frontend Patterns
2kxu-xiang/everything-claude-code-zh
Frontend development patterns for React, Next.js, state management, performance optimization, and UI best practices.
Swift Protocol Di Testing
2kxu-xiang/everything-claude-code-zh
基于协议的依赖注入,用于可测试的Swift代码——使用聚焦协议和Swift Testing模拟文件系统、网络和外部API。
Swift Concurrency 6 2
2kxu-xiang/everything-claude-code-zh
Swift 6.2 可接近的并发性 — 默认单线程,@concurrent 用于显式后台卸载,隔离一致性用于主 actor 类型。
Swift Protocol Di Testing
2kxu-xiang/everything-claude-code-zh
基于协议的依赖注入(Protocol-based Dependency Injection),通过精简的协议和 Swift 测试框架(Swift Testing)来模拟文件系统、网络和外部 API,编写可测试的 Swift 代码。
Browse the most popular Claude skills, all mobile development skills, or write your own with the skills generator.