guide-swift-concurrency
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGuide Skill — This is an expert workflow/pattern guide, not API reference documentation. Originally from twostraws/Swift-Concurrency-Agent-Skill by Paul Hudson. MIT License.
Guide Skill — 这是一份专家级工作流/模式指南,而非API参考文档。 原文出自 Paul Hudson 的 twostraws/Swift-Concurrency-Agent-Skill。采用 MIT 许可证。
Swift Concurrency Patterns
Swift并发模式
Review and write Swift concurrency code for correctness, modern API usage, and adherence to project conventions. Report only genuine problems — do not nitpick or invent issues.
审查并编写Swift并发代码,确保正确性、现代API使用以及符合项目约定。仅报告真实存在的问题——不要吹毛求疵或凭空捏造问题。
Core Instructions
核心说明
- Target Swift 6.2 or later with strict concurrency checking.
- Prefer structured concurrency (task groups) over unstructured ().
Task {} - Prefer Swift concurrency over GCD for new code. GCD is still acceptable in low-level code, framework interop, or performance-critical synchronous work.
- Do not suggest to fix compiler errors — prefer actors, value types, or
@unchecked Sendableparameters.sending
- 针对Swift 6.2或更高版本,启用严格并发检查。
- 优先使用结构化并发(任务组)而非非结构化的。
Task {} - 新代码优先使用Swift并发而非GCD。在底层代码、框架互操作或性能关键的同步工作中,GCD仍然是可接受的。
- 不要建议使用来修复编译器错误——优先选择actors、值类型或
@unchecked Sendable参数。sending
Review Process
审查流程
- Scan for known-dangerous patterns using .
references/hotspots.md - Check for Swift 6.2 concurrency behavior using .
references/new-features.md - Validate actor usage for reentrancy and isolation using .
references/actors.md - Ensure structured concurrency is preferred using .
references/structured.md - Check unstructured task usage using .
references/unstructured.md - Verify cancellation handling using .
references/cancellation.md - Validate async stream and continuation usage using .
references/async-streams.md - Check bridging code between sync and async using .
references/bridging.md - Review legacy concurrency migrations using .
references/interop.md - Cross-check against common failure modes using .
references/bug-patterns.md - If strict-concurrency errors exist, map diagnostics to fixes using .
references/diagnostics.md - If reviewing tests, check async test patterns using .
references/testing.md
If doing partial work, load only the relevant reference files.
- 使用扫描已知危险模式。
references/hotspots.md - 借助检查Swift 6.2的并发行为。
references/new-features.md - 通过验证actors的可重入性和隔离性使用情况。
references/actors.md - 确保优先采用结构化并发,参考。
references/structured.md - 使用检查非结构化任务的使用。
references/unstructured.md - 通过验证取消操作的处理。
references/cancellation.md - 借助验证异步流和continuation的使用。
references/async-streams.md - 使用检查同步与异步之间的桥接代码。
references/bridging.md - 参考审查遗留并发代码的迁移。
references/interop.md - 通过对照常见故障模式。
references/bug-patterns.md - 若存在严格并发错误,使用将诊断信息映射到修复方案。
references/diagnostics.md - 若审查测试代码,使用检查异步测试模式。
references/testing.md
若仅处理部分工作,只需加载相关的参考文件即可。
References
参考文档
| Topic | Reference |
|---|---|
| Grep targets for code review — known-dangerous patterns | |
Swift 6.2: default isolation, | |
| Actor reentrancy, global actor inference, isolation patterns | |
Task groups, | |
| |
Cooperative cancellation, | |
| |
Checked continuations, wrapping delegates, | |
| GCD migration, Combine to AsyncSequence, completion handlers, locks | |
| Common concurrency failure modes LLMs produce and their fixes | |
| Strict-concurrency compiler errors mapped to likely fixes | |
| Async test patterns, race detection, avoiding timing-based tests | |
| 主题 | 参考文件 |
|---|---|
| 代码审查的Grep目标——已知危险模式 | |
Swift 6.2:默认隔离、 | |
| Actor可重入性、全局Actor推断、隔离模式 | |
任务组、 | |
| |
协作式取消、 | |
| |
受检continuation、包装委托、 | |
| GCD迁移、Combine转AsyncSequence、完成处理程序、锁 | |
| 大语言模型生成的常见并发故障模式及其修复方案 | |
| 严格并发编译器错误与可能修复方案的映射 | |
| 异步测试模式、竞态检测、避免基于时序的测试 | |