Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

swift-concurrency-updates

БесплатноБез исполняемых скриптовНе проверен

Swift 6.2 concurrency updates including default MainActor inference, @concurrent for background work, isolated conformances, and approachable concurrency…

rshankrasот rshankras★ 922 звезды на GitHub

Об этом скилле

Swift 6.2 Concurrency Updates

Swift 6.2 introduces "Approachable Concurrency" -- a set of changes that make strict concurrency dramatically easier to adopt. Code runs on @MainActor by default, async functions stay on the calling actor, and you explicitly request background execution with @concurrent.

This skill covers only the Swift 6.2 specific changes. For general concurrency patterns (actors, TaskGroup, AsyncSequence, Sendable, cancellation), see the swift/concurrency-patterns skill.

When This Skill Activates

  • User is adopting Swift 6.2 concurrency features
  • User asks about default MainActor inference or the "infer main actor" build setting
  • User encounters data-race errors that Swift 6.2 resolves
  • User asks about @concurrent, isolated conformances, or approachable concurrency
  • User wants to migrate from Swift 6.0/6.1 strict concurrency to 6.2
  • User asks how async functions behave differently in Swift 6.2
  • User needs to offload CPU-intensive work to a background thread in Swift 6.2

What Changed in Swift 6.2 vs Before

Swift 6.2 Changes at a Glance

Feature Before (6.0/6.1) After (6.2)
Default isolation Nothing inferred; manual @MainActor everywhere Opt-in mode infers @MainActor on everything
Async function execution Hops to generic concurrent executor Stays on calling actor
@MainActor type conforming to protocol Compiler error for non-isolated protocols Isolated conformances: @MainActor Protocol
Background execution Task.detached or manual nonisolated functions @concurrent attribute
Global/static mutable state Required @MainActor annotation or Sendable Default MainActor mode handles it automatically

1. Async Functions Stay on the Calling Actor

In Swift 6.2, async functions without specific actor isolation stay on whatever actor called them, instead of hopping to the generic concurrent executor as in 6.0/6.1 -- eliminating a common source of data-race errors with no code changes required.


2. Default MainActor Inference Mode

An opt-in build setting that makes all code implicitly @MainActor unless explicitly opted out with nonisolated.

Enabling It

Xcode: Build Settings > Swift Compiler - Concurrency > "Default Actor Isolation" > "MainActor"

Swift Package Manager:

.executableTarget(
    name: "MyApp",
    swiftSettings: [
        .defaultIsolation(MainActor.self)
    ]
)

With this enabled, app-level types no longer need explicit @MainActor annotations -- including global/static mutable state, which otherwise needs an explicit @MainActor static let ....

When to Use Default MainActor Inference

Target Type Recommended? Reason
App target Yes Apps are UI-driven; most code belongs on MainActor
Script / executable Yes Scripts are sequential; MainActor default is natural
Library / framework No Libraries must not impose actor isolation on consumers
Package plugin No Same reasoning as libraries

Opting Out with nonisolated

When a type or function genuinely needs to run off the main actor, mark it nonisolated:

nonisolated struct ImageProcessor {
    func processImage(_ data: Data) -> UIImage {
        // Runs on any thread, not MainActor
        ...
    }
}

3. Isolated Conformances

Isolated conformances let a @MainActor type conform to a protocol that does not require actor isolation, using extension Type: @MainActor ProtocolName. Before Swift 6.2, this produced a compiler error about the main actor-isolated conformance crossing an isolation boundary.

protocol Exportable {
    func export()
}

@MainActor
final class StickerModel {
    let processor: PhotoProcessor
    func doExport() { processor.exportAsPNG() }
}

// ✅ Swift 6.2 -- isolated conformance
extension StickerModel: @MainActor Exportable {
    func export() {
        processor.exportAsPNG()  // Works: conformance is MainActor-isolated
    }
}

The conformance can only be used from a context that shares the same isolation domain:

// ✅ Used within @MainActor context -- OK
@MainActor
func exportAll(_ items: [any Exportable]) {
    for item in items { item.export() }
}

// ❌ Used outside @MainActor -- compile error
nonisolated func exportAll(_ items: [any Exportable]) {
    for item in items {
        item.export()  // Error: isolated conformance not available here
    }
}

4. @concurrent -- Explicit Background Execution

@concurrent explicitly offloads a function to the background thread pool, replacing the pattern of using Task.detached for compute-intensive operations.

nonisolated struct ImageProcessor {
    @concurrent
    func resize(image: Data, to size: CGSize) async -> Data {
        // Runs on background thread pool
        ...
    }
}

// Caller (on MainActor):
let resized = await ImageProcess
Полный SKILL.md на GitHub

Установить swift-concurrency-updates в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Glob
Grep

Вложенные файлы

rules/swiftlint.yml

FAQ

Что делает скилл swift-concurrency-updates?

Swift 6.2 concurrency updates including default MainActor inference, @concurrent for background work, isolated conformances, and approachable concurrency migration. Use when adopting Swift 6.2 concurrency features or fixing data-race errors.

Как установить скилл swift-concurrency-updates?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл swift-concurrency-updates запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить swift-concurrency-updates с