Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计通过

swift-concurrencySwift 并发

Agent Skill

swift-concurrency 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

235

周安装

10

GitHub Stars

742

下载量

82
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/sozercan/kaset --skill swift-concurrency

简介

用于 Swift 并发编程相关信息的检索和整理。

  • 适合查找异步处理、线程安全和性能优化资料。swift-concurrency 属于研究检索类 Skill,可作为该场景下的辅助能力补充。
  • 可通过 GitHub 安装,需确认是否访问外部资源。
  • 建议结合 Apple 官方文档验证技术方案的准确性。
  • 适用于 iOS/macOS 应用开发中的并发场景参考。

SKILL.md

Swift Concurrency

Overview

This skill provides expert guidance on Swift Concurrency, covering modern async/await patterns, actors, tasks, Sendable conformance, and migration to Swift 6. Use this skill to help developers write safe, performant concurrent code and navigate the complexities of Swift's structured concurrency model.

Agent Behavior Contract (Follow These Rules)

  1. Analyze the project/package file to find out which Swift language mode (Swift 5.x vs Swift 6) and which Xcode/Swift toolchain is used when advice depends on it.
  2. Before proposing fixes, identify the isolation boundary: @MainActor, custom actor, actor instance isolation, or nonisolated.
  3. Do not recommend @MainActor as a blanket fix. Justify why main-actor isolation is correct for the code.
  4. Prefer structured concurrency (child tasks, task groups) over unstructured tasks. Use Task.detached only with a clear reason.
  5. If recommending @preconcurrency, @unchecked Sendable, or nonisolated(unsafe), require:

- a documented safety invariant - a follow-up ticket to remove or migrate it

  1. For migration work, optimize for minimal blast radius (small, reviewable changes) and add verification steps.
  2. Course references are for deeper learning only. Use them sparingly and only when they clearly help answer the developer's question.

Project Settings Intake (Evaluate Before Advising)

Concurrency behavior depends on build settings. Always try to determine:

  • Default actor isolation (is the module default @MainActor or nonisolated?)
  • Strict concurrency checking level (minimal/targeted/complete)
  • Whether upcoming features are enabled (especially NonisolatedNonsendingByDefault)
  • Swift language mode (Swift 5.x vs Swift 6) and SwiftPM tools version

Manual checks (no scripts)

  • SwiftPM:

- Check Package.swift for .defaultIsolation(MainActor.self). - Check Package.swift for .enableUpcomingFeature("NonisolatedNonsendingByDefault"). - Check for strict concurrency flags: .enableExperimentalFeature("StrictConcurrency=targeted") (or similar). - Check tools version at the top: // swift-tools-version:...

  • Xcode projects:

- Search project.pbxproj for: - SWIFT_DEFAULT_ACTOR_ISOLATION - SWIFT_STRICT_CONCURRENCY - SWIFT_UPCOMING_FEATURE_ (and/or SWIFT_ENABLE_EXPERIMENTAL_FEATURES)

If any of these are unknown, ask the developer to confirm them before giving migration-sensitive guidance.

Quick Decision Tree

When a developer needs concurrency guidance, follow this decision tree:

  1. Starting fresh with async code?

- Read references/async-await-basics.md for foundational patterns - For parallel operations → references/tasks.md (async let, task groups)

  1. Protecting shared mutable state?

- Need to protect class-based state → references/actors.md (actors, @MainActor) - Need thread-safe value passing → references/sendable.md (Sendable conformance)

  1. Managing async operations?

- Structured async work → references/tasks.md (Task, child tasks, cancellation) - Streaming data → references/async-sequences.md (AsyncSequence, AsyncStream)

  1. Working with legacy frameworks?

- Core Data integration → references/core-data.md - General migration → references/migration.md

  1. Performance or debugging issues?

- Slow async code → references/performance.md (profiling, suspension points) - Testing concerns → references/testing.md (XCTest, Swift Testing)

  1. Understanding threading behavior?

- Read references/threading.md for thread/task relationship and isolation

  1. Memory issues with tasks?

- Read references/memory-management.md for retain cycle prevention

Triage-First Playbook (Common Errors -> Next Best Move)

  • SwiftLint concurrency-related warnings

- Use references/linting.md for rule intent and preferred fixes; avoid dummy awaits as "fixes".

  • SwiftLint async_without_await warning

- Remove async if not required; if required by protocol/override/@concurrent, prefer narrow suppression over adding fake awaits. See references/linting.md.

  • "Sending value of non-Sendable type... risks causing data races"

- First: identify where the value crosses an isolation boundary - Then: use references/sendable.md and references/threading.md (especially Swift 6.2 behavior changes)

  • "Main actor-isolated... cannot be used from a nonisolated context"

- First: decide if it truly belongs on @MainActor - Then: use references/actors.md (global actors, nonisolated, isolated parameters) and references/threading.md (default isolation)

  • "Class property 'current' is unavailable from asynchronous contexts" (Thread APIs)

- Use references/threading.md to avoid thread-centric debugging and rely on isolation + Instruments

  • XCTest async errors like "wait(...) is unavailable from asynchronous contexts"

- Use references/testing.md (await fulfillment(of:) and Swift Testing patterns)

  • Core Data concurrency warnings/errors

- Use references/core-data.md (DAO/NSManagedObjectID, default isolation conflicts)

Core Patterns Reference

When to Use Each Concurrency Tool

async/await - Making existing synchronous code asynchronous

// Use for: Single asynchronous operations
func fetchUser() async throws -> User {
    try await networkClient.get("/user")
}

async let - Running multiple independent async operations in parallel

// Use for: Fixed number of parallel operations known at compile time
async let user = fetchUser()
async let posts = fetchPosts()
let profile = try await (user, posts)

Task - Starting unstructured asynchronous work

// Use for: Fire-and-forget operations, bridging sync to async contexts
Task {
    await updateUI()
}

Task Group - Dynamic parallel operations with structured concurrency

// Use for: Unknown number of parallel operations at compile time
await withTaskGroup(of: Result.self) { group in
    for item in items {
        group.addTask { await process(item) }
    }
}

Actor - Protecting mutable state from data races

// Use for: Shared mutable state accessed from multiple contexts
actor DataCache {
    private var cache: [String: Data] = [:]
    func get(_ key: String) -> Data? { cache[key] }
}

@MainActor - Ensuring UI updates on main thread

// Use for: View models, UI-related classes
@MainActor
class ViewModel: ObservableObject {
    @Published var data: String = ""
}

Common Scenarios

Scenario: Network request with UI update

Task { @concurrent in
    let data = try await fetchData() // Background
    await MainActor.run {
        self.updateUI(with: data) // Main thread
    }
}

Scenario: Multiple parallel network requests

async let users = fetchUsers()
async let posts = fetchPosts()
async let comments = fetchComments()
let (u, p, c) = try await (users, posts, comments)

Scenario: Processing array items in parallel

await withTaskGroup(of: ProcessedItem.self) { group in
    for item in items {
        group.addTask { await process(item) }
    }
    for await result in group {
        results.append(result)
    }
}

Swift 6 Migration Quick Guide

Key changes in Swift 6:

  • Strict concurrency checking enabled by default
  • Complete data-race safety at compile time
  • Sendable requirements enforced on boundaries
  • Isolation checking for all async boundaries

For detailed migration steps, see references/migration.md.

Reference Files

Load these files as needed for specific topics:

  • async-await-basics.md - async/await syntax, execution order, async let, URLSession patterns
  • tasks.md - Task lifecycle, cancellation, priorities, task groups, structured vs unstructured
  • threading.md - Thread/task relationship, suspension points, isolation domains, nonisolated
  • memory-management.md - Retain cycles in tasks, memory safety patterns
  • actors.md - Actor isolation, @MainActor, global actors, reentrancy, custom executors, Mutex
  • sendable.md - Sendable conformance, value/reference types, @unchecked, region isolation
  • linting.md - Concurrency-focused lint rules and SwiftLint async_without_await
  • async-sequences.md - AsyncSequence, AsyncStream, when to use vs regular async methods
  • core-data.md - NSManagedObject sendability, custom executors, isolation conflicts
  • performance.md - Profiling with Instruments, reducing suspension points, execution strategies
  • testing.md - XCTest async patterns, Swift Testing, concurrency testing utilities
  • migration.md - Swift 6 migration strategy, closure-to-async conversion, @preconcurrency, FRP migration

Best Practices Summary

  1. Prefer structured concurrency - Use task groups over unstructured tasks when possible
  2. Minimize suspension points - Keep actor-isolated sections small to reduce context switches
  3. Use @MainActor judiciously - Only for truly UI-related code
  4. Make types Sendable - Enable safe concurrent access by conforming to Sendable
  5. Handle cancellation - Check Task.isCancelled in long-running operations
  6. Avoid blocking - Never use semaphores or locks in async contexts
  7. Test concurrent code - Use proper async test methods and consider timing issues

Verification Checklist (When You Change Concurrency Code)

  • Confirm build settings (default isolation, strict concurrency, upcoming features) before interpreting diagnostics.
  • After refactors:

- Run tests, especially concurrency-sensitive ones (see references/testing.md). - If performance-related, verify with Instruments (see references/performance.md). - If lifetime-related, verify deinit/cancellation behavior (see references/memory-management.md).

Glossary

See references/glossary.md for quick definitions of core concurrency terms used across this skill.


Note: This skill is based on the comprehensive Swift Concurrency Course by Antoine van der Lee.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

29.6%
按下载量换算24

OpenCode

20.22%
按下载量换算17

windsurf

15.29%
按下载量换算13

trae

11.75%
按下载量换算10

Cursor

8.41%
按下载量换算7

Codex

3.26%
按下载量换算3

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills