swift-concurrency-6-2

Implements Swift 6.2 approachable concurrency patterns with MainActor defaults and @concurrent offloading.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill swift-concurrency-6-2-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-concurrency-6-2
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/swift-concurrency-6-2
Command: npx skills add https://github.com/Femad-6/my-skills --skill swift-concurrency-6-2-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Migrating Swift code to Swift 6.2 often triggers data-race compiler errors caused by implicit background offloading of async functions, unsafe global state, and protocol conformances on MainActor types. This Skill provides the patterns and migration steps to adopt Swift 6.2's approachable concurrency model correctly. ## Core Features & Use Cases - Single-Threaded by Default: Explains how async functions stay on the calling actor in Swift 6.2, eliminating common data-race errors without extra annotations. - Isolated Conformances: Shows how MainActor types can conform to non-isolated protocols safely using @MainActor conformances. - @concurrent Offloading: Guides explicit background execution for CPU-intensive work like image processing, with correct nonisolated and await usage. - Use Case: When migrating a SwiftUI app to Xcode 26 and hitting "Sending 'self' risks causing data races" errors, apply these patterns to fix the errors by keeping code on the MainActor and offloading only heavy computations with @concurrent. ## Quick Start Ask the assistant to migrate my Swift class to Swift 6.2 approachable concurrency and fix the data-race compiler errors.

Frequently Asked Questions about swift-concurrency-6-2

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix data-race errors when migrating to Swift 6.2?

Swift 6.2 keeps async functions on the calling actor by default, so most data-race errors disappear once you enable the approachable concurrency build settings. For remaining issues, annotate shared state with @MainActor or offload heavy work explicitly with @concurrent.

How do I offload CPU-intensive work to a background thread in Swift 6.2?

Mark the containing type as nonisolated, add @concurrent to the function, ensure it is async, and use await at call sites. This explicitly moves work like image processing to the concurrent thread pool while the rest of your code stays on the calling actor.

What is an isolated conformance in Swift 6.2?

An isolated conformance lets a MainActor type conform to a non-isolated protocol by writing extension MyType: @MainActor SomeProtocol. The compiler guarantees the conformance is only used on the main actor, producing an error if accessed from a nonisolated context.

Does Swift 6.2 run async functions in the background by default?

No. Swift 6.2 changed the default so async functions stay on the calling actor instead of being implicitly offloaded to background threads. Background execution now requires an explicit @concurrent annotation.

How do I enable MainActor default inference in a Swift package?

Enable it through the Swift Compiler Concurrency build settings in Xcode, or use the SwiftSettings API in your Package.swift manifest. The mode is opt-in and recommended for apps, scripts, and other executable targets.

When should I avoid using @concurrent in Swift code?

Avoid applying @concurrent to every async function, since most code does not need background execution. Reserve it for CPU-intensive work like image processing or compression, and profile with Instruments first to confirm actual bottlenecks.