skillfed

swift-concurrency-6-2

Master Swift 6.2's concurrency paradigm where code executes on a single thread by default and background work requires explicit opt-in via @concurrent. This skill teaches you how async functions now remain on their calling actor, eliminating the implicit offloading that caused data-race errors in earlier versions. Learn to use isolated conformances for MainActor types, protect global state, and migrate existing projects incrementally while leveraging the compiler's safety guarantees.

Swift Concurrency 6.2 helps you migrate projects to single-threaded-by-default concurrency and eliminate data-race errors.

AI-generated summary based on this skill's SKILL.md

234,207 35,692 MIT updated by affaan-m

Install

affaan-m/ECC/swift-concurrency-6-2 · repository language: JavaScript

CLI (skillfed)coming soon
git clone https://github.com/affaan-m/ECC
cp -r ECC/skills/swift-concurrency-6-2 ~/.claude/skills/swift-concurrency-6-2

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

What are swift 6.2 concurrency patterns for data safety?

swift-concurrency-6-2 introduces a single-threaded default where async functions remain on their calling actor instead of implicitly offloading to background threads. This eliminates the data-race errors common in earlier versions. You explicitly opt into background work using @concurrent for CPU-intensive tasks. The key pattern is: keep UI and shared state on MainActor, mark background work with @concurrent, and use isolated conformances to safely implement protocols on MainActor types while maintaining actor isolation guarantees.

How do I fix data race errors in Swift 6.2?

swift-concurrency-6-2 fixes data races by changing the default behavior: async code no longer implicitly jumps to background threads. Instead, it stays on the calling actor. To resolve existing data-race errors, identify shared mutable state and protect it with actor isolation or MainActor. Use @concurrent to explicitly mark functions that should run in the background. Enable Approachable Concurrency build settings in Xcode to get compiler guidance. Migrate incrementally—the compiler will flag unsafe patterns and guide you toward safe isolated conformances and explicit offloading.

What is MainActor isolation and how do isolated conformances work?

swift-concurrency-6-2's MainActor isolation ensures code runs on the main thread, essential for UI updates and shared state. Isolated conformances let you implement protocols on MainActor types while preserving isolation: mark protocol methods as isolated(MainActor) so they execute on the main thread without losing actor guarantees. This pattern is safer than nonisolated, which breaks isolation. Use isolated conformances when adopting Codable, Equatable, or custom protocols on MainActor types to maintain data-race safety while meeting protocol requirements.

When should I use @concurrent in Swift 6.2 for background work?

swift-concurrency-6-2's @concurrent attribute explicitly marks functions for background execution, replacing the implicit offloading of earlier versions. Use @concurrent for CPU-intensive work—image processing, heavy calculations, file I/O—that shouldn't block the main thread. Apply it to functions that don't need MainActor isolation and can safely run in the background. The compiler enforces that @concurrent functions don't access main-thread-only state unsafely, making it the recommended way to opt into background execution while maintaining actor safety.

How do I enable Approachable Concurrency in Xcode for Swift 6.2?

swift-concurrency-6-2's Approachable Concurrency setting is configured in Xcode's build settings under Swift Compiler - Upcoming Features. Enable it to activate the single-threaded default and get compiler diagnostics for data-race issues. This setting enforces that async functions stay on their calling actor and requires explicit @concurrent for background work. It's essential for migrating from Swift 6.1 and earlier—enable it incrementally, fix compiler warnings, and gradually adopt isolated conformances and explicit offloading patterns.

What's the difference between nonisolated and @concurrent in Swift 6.2?

swift-concurrency-6-2 distinguishes these for protocol conformance safety: nonisolated removes isolation entirely, breaking actor guarantees and risking data races on MainActor types. @concurrent explicitly opts into background execution while maintaining actor safety—the compiler prevents unsafe access to isolated state. Use isolated conformances (isolated(MainActor)) for MainActor protocols instead of nonisolated. Reserve @concurrent for functions designed to run in the background. This hierarchy—isolated > @concurrent > nonisolated—reflects increasing risk and should guide your migration strategy.

SKILL.md

rendered from the published skill — quoted content, verbatim

Swift 6.2 Approachable Concurrency

Patterns for adopting Swift 6.2's concurrency model where code runs single-threaded by default and concurrency is introduced explicitly. Eliminates common data-race errors without sacrificing performance.

When to Activate

  • Migrating Swift 5.x or 6.0/6.1 projects to Swift 6.2
  • Resolving data-race safety compiler errors
  • Designing MainActor-based app architecture
  • Offloading CPU-intensive work to background threads
  • Implementing protocol conformances on MainActor-isolated types
  • Enabling Approachable Concurrency build settings in Xcode 26

Core Problem: Implicit Background Offloading

In Swift 6.1 and earlier, async functions could be implicitly offloaded to background threads, causing data-race errors even in seemingly safe code:

```swift // Swift 6.1: ERROR @MainActor final class StickerModel { let photoProcessor = PhotoProcessor()

func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {
    guard

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 1 file
skills/swift-concurrency-6-2/SKILL.md

Related skills

Tags

actor-isolation thread-safety compiler-driven migration-guide performance-tuning ui-architecture data-race-prevention explicit-concurrency swift-6-2