Understand Swift 6.2 concurrency changes and apply them safely in code.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "swift-concurrency-6-2" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/swift-concurrency-6-2/SKILL.md 2. Save it as ~/.claude/skills/swift-concurrency-6-2/SKILL.md 3. Reload skills and tell me it's ready
Explain Swift 6.2 Approachable Concurrency in simple terms, including single-threaded by default, what @concurrent does, and what isolated conformances mean for main-actor types, with a simple example.
A clear explanation summarizing the key concepts with sample code.
I have some legacy Swift concurrency code. Refactor it for the Swift 6.2 concurrency model, identify what should keep default isolation, what should explicitly use @concurrent for background work, and explain why.
Refactoring recommendations, updated code examples, and explanations for each change.
Review this Swift code and determine whether protocol conformances on main-actor-related types should use isolated conformances, then point out potential thread-safety issues and fixes.
A review of the conformances, including risks, fixes, and example implementations.
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.
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 6.1: ERROR
@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 }
// Error: Sending 'self.photoProcessor' risks causing data races
return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)
}
}
Swift 6.2 fixes this: async functions stay on the calling actor by default.
// Swift 6.2: OK — async stays on MainActor, no data race
@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 }
return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)
}
}
MainActor types can now conform to non-isolated protocols safely:
protocol Exportable {
func export()
}
// Swift 6.1: ERROR — crosses into main actor-isolated code
// Swift 6.2: OK with isolated conformance
extension StickerModel: @MainActor Exportable {
func export() {
photoProcessor.exportAsPNG()
}
}
The compiler ensures the conformance is only used on the main actor:
// OK — ImageExporter is also @MainActor
@MainActor
struct ImageExporter {
var items: [any Exportable]
mutating func add(_ item: StickerModel) {
items.append(item) // Safe: same actor isolation
}
}
// ERROR — nonisolated context can't use MainActor conformance
nonisolated struct ImageExporter {
var items: [any Exportable]
mutating func add(_ item: StickerModel) {
items.append(item) // Error: Main actor-isolated conformance cannot be used here
}
}
Protect global/static state with MainActor:
// Swift 6.1: ERROR — non-Sendable type may have shared mutable state
final class StickerLibrary {
static let shared: StickerLibrary = .init() // Error
}
// Fix: Annotate with @MainActor
@MainActor
final class StickerLibrary {
static let shared: StickerLibrary = .init() // OK
}
Swift 6.2 introduces a mode where MainActor is inferred by default — no manual annotations needed:
// With MainActor default inference enabled:
final class StickerLibrary {
static let shared: StickerLibrary = .init() // Implicitly @MainActor
}
final class StickerModel {
let photoProcessor: PhotoProcessor
var selection: [PhotosPickerItem] // Implicitly @MainActor
}
extension StickerModel: Exportable { // Implicitly @MainActor conformance
func export() {
photoProcessor.exportAsPNG()
}
}
This mode is opt-in and recommended for apps, scripts, and other executable targets.
When you need actual parallelism, explicitly offload with @concurrent:
…
Conduct systematic literature reviews with search planning, screening, synthesis, and citation checks.
Checks homelab network readiness before VLAN, DNS, firewall, or VPN changes.
Improve interface polish through spacing, typography, motion, and interaction details.
Design safer EMR/EHR workflows, prescribing modules, and accessible clinical data-entry interfaces.
Autonomously build higher-quality apps through iterative generator-evaluator agent workflows.
Research current facts, compare options, and produce evidence-based recommendations.
Add expert Swift concurrency guidance for safer code, better performance, and Swift 6 migration.
Build thread-safe Swift persistence with actors, cache, and file-backed storage.
Speed up complex tasks with parallel execution while preserving correctness.
Learn Swift conventions, naming, and async patterns for DAT SDK iOS development.