Token导航 LogoToken导航

Agent Skill · 开发

swift-concurrency(Swift 并发)

swift-concurrency 用于记录任务执行中的错误、用户纠正、经验和能力缺口,适合在 Codex、Claude、Cursor、Gemini CLI 中希望让 Agent 持续沉淀问题、修正和最佳实践时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

swift-concurrency 是开发类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在开发类的 21,746 个 Skill 里排第 1,510。

总安装 27,936周安装 1,182GitHub Stars 469下载 9,792核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:swift-concurrency(Swift 并发)
来源仓库:https://github.com/dpearson2699/swift-ios-skills
仓库路径:skills/swift-concurrency
安装命令:
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-concurrency
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-concurrency

这个 Skill 是做什么的

开发类 Skill 面向写代码、改代码和排查问题,一般会读写仓库文件,部分还会执行构建或测试命令。

解决 Swift 6.2 并发错误并采用数据争用安全的异步模式。

使用结构化分类工作流程诊断和修复参与者隔离、可发送一致性和严格的并发编译器诊断 应用 SE-0466 默认 MainActor 隔离、SE-0461 非隔离(非发送)、@concurrent 函数和 Task.immediate 以实现最小的行为更改 设计基于参与者的架构、TaskGroup 和 async let 的结构化并发以及适当的任务取消模式 从 @preconcurrency 导入迁移到完整的 Swift 6 严格并发,同时处理 Actor 重入和交叉隔离回调

来源仓库内路径:skills/swift-concurrency

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-co…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

swift-concurrency 怎么安装?

在终端执行 npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-concurrency。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

swift-concurrency 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

swift-concurrency 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

swift-concurrency 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

swift-concurrency 用的人多吗?

公开数据是累计安装 27,936 次,近一周安装 1,182 次,下载 9,792 次,GitHub 469 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

swift-concurrency 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
skill-vetter

技能审查员 · OpenClaw

8,779,018986操作浏览器MIT-0通过
ontology

本体论 · OpenClaw

6,636,960576只读MIT-0通过
entra-app-registration

内部应用程序注册 · Codex、Claude

6,631,872764接触敏感数据未明确通过
entra-app-registration

内部应用程序注册 · Codex、Claude

3,757,680201接触敏感数据未明确通过
nano-banana-pro

纳米香蕉专业版 · OpenClaw

3,526,898364接触敏感数据MIT-0有提醒
swift-concurrency

Swift 并发 · 本页

27,936469需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Swift Concurrency

Review, fix, and write concurrent Swift code targeting Swift 6.3+. Apply actor isolation, Sendable safety, and modern concurrency patterns with minimal behavior changes.

Contents

Triage Workflow

When diagnosing a concurrency issue, follow this sequence:

Step 1: Capture context

  • Copy the exact compiler diagnostic(s) and the offending symbol(s).
  • Identify the project's concurrency settings:

- Swift language version (must be 6.2+). - Whether approachable concurrency (default MainActor isolation) is enabled. - Strict concurrency checking level (Complete / Targeted / Minimal).

  • Determine the current actor context of the code (@MainActor, custom actor, nonisolated) and whether a default isolation mode is active.
  • Confirm whether the code is UI-bound or intended to run off the main actor.

Step 2: Apply the smallest safe fix

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

SituationRecommended fix
UI-bound typeAnnotate the type or relevant members with @MainActor.
Protocol conformance on MainActor typeUse an isolated conformance: extension Foo: @MainActor Proto.
Global / static stateProtect with @MainActor or move into an actor.
Background work neededUse a @concurrent async function on a nonisolated type.
Sendable errorPrefer immutable value types. Add Sendable only when correct.
Cross-isolation callbackUse sending parameters (SE-0430) for finer control.

Step 3: Verify

  • Rebuild and confirm the diagnostic is resolved.
  • Check for new warnings introduced by the fix.
  • Ensure no unnecessary @unchecked Sendable or nonisolated(unsafe) was added.

Swift 6.2 Language Changes

Swift 6.2 introduces "approachable concurrency" -- a set of language changes that make concurrent code safer by default while reducing annotation burden.

SE-0466: Default MainActor Isolation

With the -default-isolation MainActor compiler flag (or the Xcode 26 "Approachable Concurrency" build setting), all code in a module runs on @MainActor by default unless explicitly opted out.

Effect: Eliminates most data-race safety errors for UI-bound code and global/static state without writing @MainActor everywhere.

// With default MainActor isolation enabled, these are implicitly @MainActor:
final class StickerLibrary {
    static let shared = StickerLibrary()  // safe -- on MainActor
    var stickers: [Sticker] = []
}

final class StickerModel {
    let photoProcessor = PhotoProcessor()
    var selection: [PhotosPickerItem] = []
}

// Conformances are also implicitly isolated:
extension StickerModel: Exportable {
    func export() {
        photoProcessor.exportAsPNG()
    }
}

When to use: Recommended for apps, scripts, and other executable targets where most code is UI-bound. Not recommended for library targets that should remain actor-agnostic.

SE-0461: nonisolated(nonsending)

Nonisolated async functions now stay on the caller's actor by default instead of hopping to the global concurrent executor. This is the nonisolated(nonsending) behavior.

class PhotoProcessor {
    func extractSticker(data: Data, with id: String?) async -> Sticker? {
        // In Swift 6.2+, this runs on the caller's actor (e.g., MainActor)
        // instead of hopping to a background thread.
        // ...
    }
}

@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
        }
        // No data race -- photoProcessor stays on MainActor
        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)
    }
}

Use @concurrent to explicitly request background execution when needed.

@concurrent Attribute

@concurrent ensures a function always runs on the concurrent thread pool, freeing the calling actor to run other tasks.

class PhotoProcessor {
    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 {
        // Expensive image processing -- runs on background thread pool
        // ...
    }
}

To move a function to a background thread:

  1. Ensure the containing type is nonisolated (or the function itself is).
  2. Add @concurrent to the function.
  3. Add async if not already asynchronous.
  4. Add await at call sites.
nonisolated struct PhotoProcessor {
    @concurrent
    func process(data: Data) async -> ProcessedPhoto? { /* ... */ }
}

// Caller:
processedPhotos[item.id] = await PhotoProcessor().process(data: data)

SE-0472: Task.immediate

Task.immediate starts executing synchronously on the current actor before any suspension point, rather than being enqueued.

Task.immediate { await handleUserInput() }

Use for latency-sensitive work that should begin without delay. There is also Task.immediateDetached which combines immediate start with detached semantics.

SE-0475: Transactional Observation (Observations)

Observations {} provides async observation of @Observable types via AsyncSequence, enabling transactional change tracking.

for await _ in Observations { model.count } {
    print("Count changed to \(model.count)")
}

Isolated Conformances

A conformance that needs MainActor state is called an *isolated conformance*. The compiler ensures it is only used in a matching isolation context.

protocol Exportable {
    func export()
}

// Isolated conformance: only usable on MainActor
extension StickerModel: @MainActor Exportable {
    func export() {
        photoProcessor.exportAsPNG()
    }
}

@MainActor
struct ImageExporter {
    var items: [any Exportable]

    mutating func add(_ item: StickerModel) {
        items.append(item)  // OK -- ImageExporter is on MainActor
    }
}

If ImageExporter were nonisolated, adding a StickerModel would fail: "Main actor-isolated conformance of 'StickerModel' to 'Exportable' cannot be used in nonisolated context."

Clock Epochs

ContinuousClock and SuspendingClock now expose .epoch (SE-0473), enabling instant comparison and conversion between clock types.

let continuous = ContinuousClock()
let elapsed = continuous.now - continuous.epoch  // Duration since system boot

Actor Isolation Rules

  1. All mutable shared state MUST be protected by an actor or global actor.
  2. @MainActor for all UI-touching code. No exceptions.
  3. Use nonisolated only for methods that access immutable (let) properties or are pure computations.
  4. Use @concurrent to explicitly move work off the caller's actor.
  5. Never use nonisolated(unsafe) unless you have proven internal synchronization and exhausted all other options.
  6. Never add manual locks (NSLock, DispatchSemaphore) inside actors.

Sendable Rules

  1. Value types (structs, enums) are automatically Sendable when all stored properties are Sendable.
  2. Actors are implicitly Sendable.
  3. @MainActor classes are implicitly Sendable. Do NOT add redundant Sendable conformance.
  4. Non-actor classes: must be final with all stored properties let and Sendable.
  5. @unchecked Sendable is a last resort. Document why the compiler cannot prove safety.
  6. Use sending parameters (SE-0430) for finer-grained isolation control.
  7. Use @preconcurrency import only for third-party libraries you cannot modify. Plan to remove it.

Structured Concurrency Patterns

Async Defer

defer blocks can now contain await (SE-0493). Use for async cleanup — closing connections, flushing buffers, or releasing resources that require an async call.

func fetchData() async throws -> Data {
    let connection = try await openConnection()
    defer { await connection.close() }
    return try await connection.read()
}

Task: Unstructured, inherits caller context.

Task { await doWork() }

Task.detached: No inherited context. Use only when you explicitly need to break isolation inheritance.

Task.immediate: Starts immediately on current actor. Use for latency-sensitive work.

Task.immediate { await handleUserInput() }

async let: Fixed number of concurrent operations.

async let a = fetchA()
async let b = fetchB()
let result = try await (a, b)

TaskGroup: Dynamic number of concurrent operations.

try await withThrowingTaskGroup(of: Item.self) { group in
    for id in ids {
        group.addTask { try await fetch(id) }
    }
    for try await item in group { process(item) }
}

Task Cancellation

  • Cancellation is cooperative. Check Task.isCancelled or call try Task.checkCancellation() in loops.
  • Use .task modifier in SwiftUI -- it handles cancellation on view disappear.
  • Use withTaskCancellationHandler for cleanup.
  • Cancel stored tasks in deinit or onDisappear.

Actor Reentrancy

Actors are reentrant. State can change across suspension points.

// WRONG: State may change during await
actor Counter {
    var count = 0
    func increment() async {
        let current = count
        await someWork()
        count = current + 1  // BUG: count may have changed
    }
}

// CORRECT: Mutate synchronously, no reentrancy risk
actor Counter {
    var count = 0
    func increment() { count += 1 }
}

AsyncSequence and AsyncStream

Use AsyncStream to bridge callback/delegate APIs:

let stream = AsyncStream<Location> { continuation in
    let delegate = LocationDelegate { location in
        continuation.yield(location)
    }
    continuation.onTermination = { _ in delegate.stop() }
    delegate.start()
}

Use withCheckedContinuation / withCheckedThrowingContinuation for single-value callbacks. Resume exactly once.

@Observable and Concurrency

  • @Observable classes should be @MainActor for view models.
  • Use @State to own an @Observable instance (replaces @StateObject).
  • Use Observations {} (SE-0475) for async observation of @Observable properties as an AsyncSequence.

Synchronization Primitives

When actors are not the right fit — synchronous access, performance-critical paths, or bridging C/ObjC — use low-level synchronization primitives:

  • Mutex<Value> (iOS 18+, Synchronization module): Preferred lock for new code. Stores protected state inside the lock. withLock {} pattern.
  • OSAllocatedUnfairLock (iOS 16+, os module): Use when targeting older iOS versions. Supports ownership assertions for debugging.
  • Atomic<Value> (iOS 18+, Synchronization module): Lock-free atomics for simple counters and flags. Requires explicit memory ordering.

Key rule: Never put locks inside actors (double synchronization), and never hold a lock across await (deadlock risk). See references/synchronization-primitives.md for full API details, code examples, and a decision guide for choosing locks vs actors.

Common Mistakes

  1. Blocking the main actor. Heavy computation on @MainActor freezes UI. Move to a @concurrent function.
  2. Unnecessary @MainActor. Network layers, data processing, and model code do not need @MainActor. Only UI-touching code does.
  3. Actors for stateless code. No mutable state means no actor needed. Use a plain struct or function.
  4. Actors for immutable data. Use a Sendable struct, not an actor.
  5. Task.detached without good reason. Loses priority, task-local values, and cancellation propagation.
  6. Forgetting task cancellation. Store Task references and cancel them, or use the .task view modifier.
  7. Retain cycles in Tasks. Use [weak self] when capturing self in long-lived stored tasks.
  8. Semaphores in async context. DispatchSemaphore.wait() in async code will deadlock. Use structured concurrency instead.
  9. Split isolation. Mixing @MainActor and nonisolated properties in one type. Isolate the entire type consistently.
  10. MainActor.run instead of static isolation. Prefer @MainActor func over await MainActor.run {}.
  11. Using GCD APIs. Never use DispatchQueue, DispatchGroup, DispatchSemaphore, or any GCD API. Use async/await, actors, and TaskGroups instead. GCD has no data-race safety guarantees.

Review Checklist

  • All mutable shared state is actor-isolated
  • No data races (no unprotected cross-isolation access)
  • Tasks are cancelled when no longer needed
  • No blocking calls on @MainActor
  • No manual locks inside actors
  • Sendable conformance is correct (no unjustified @unchecked)
  • Actor reentrancy is handled (no state assumptions across awaits)
  • @preconcurrency imports are documented with removal plan
  • Heavy work uses @concurrent, not @MainActor
  • .task modifier used in SwiftUI instead of manual Task management

References

平台分布

Codex

38.89%
按下载量换算3,808

Claude

31.61%
按下载量换算3,095

Cursor

16.81%
按下载量换算1,646

Gemini CLI

10.34%
按下载量换算1,012

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills