跳到正文
Skillpedia
移动应用7.4k · #13248

swift-concurrency-expert

它能做什么

这个技能诊断关于 Swift 并发的编译器错误,并对 actor、主线程隔离和共享数据应用安全的修复。适合开发 Swift 6 应用的开发者。

适用场景

  • ✓Swift 显示与 actor、隔离或 Sendable 类型相关的错误的时候。
  • ✓你需要把后台工作安全地移出主线程的时候。
  • ✓你想审核现有 Swift 并发设置的时候。

技能链接

https://github.com/steipete/agent-scripts/blob/main/skills/swift-concurrency-expert/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/steipete/agent-scripts/blob/main/skills/swift-concurrency-expert/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“Xcode 提示我的视图模型有 Sendable 错误。请用最小的安全改动修复它。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会获取准确的编译器信息,找到当前的 actor 设置,并应用能保持行为不变的最小修复。除非能证明线程安全,否则它会避免不安全的捷径。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Swift Concurrency Expert

Attribution: copied from @Dimillian’s Dimillian/Skills (2025-12-31).

Overview

Review and fix Swift Concurrency issues in Swift 6.2+ codebases by applying actor isolation, Sendable safety, and modern concurrency patterns with minimal behavior changes.

Workflow

1. Triage the issue

  • Capture the exact compiler diagnostics and the offending symbol(s).
  • Identify the current actor context (@MainActor, actor, nonisolated) and whether a default actor isolation mode is enabled.
  • Confirm whether the code is UI-bound or intended to run off the main actor.

2. Apply the smallest safe fix

Prefer edits that preserve existing behavior while satisfying data-race safety.

Common fixes:

  • UI-bound types: annotate the type or relevant members with @MainActor.
  • Protocol conformance on main actor types: make the conformance isolated (e.g., extension Foo: @MainActor SomeProtocol).
  • Global/static state: protect with @MainActor or move into an actor.
  • Background work: move expensive work into a @concurrent async function on a nonisolated type or use an actor to guard mutable state.
  • Sendable errors: prefer immutable/value types; add Sendable conformance only when correct; avoid @unchecked Sendable unless you can prove thread safety.

Reference material

  • See references/swift-6-2-concurrency.md for Swift 6.2 changes, patterns, and examples.
  • See references/swiftui-concurrency-tour-wwdc.md for SwiftUI-specific concurrency guidance.
常见问题

它会改变应用的行为吗?

技能力求在满足数据竞争安全规则的同时,使行为改动最小。

什么时候允许使用未经检查的 Sendable?

根据技能说明,只有在能证明线程安全的情况下才允许。

它针对哪些 Swift 版本?

Swift 6.2 及更高版本。

详情

作者的原始描述

Swift concurrency review/fix: compiler errors, Sendable, isolation, remediation.

repo: steipete/agent-scripts

热度

GitHub 星标
7.4k
排名
#13248
许可证
MIT
更新时间
2026/10/30

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能