Skip to main content
skill CX Codex

modern-swift — Claude Code skill: async/await, actors, Sendable

modern-swift — a Claude skill that steers the agent through Swift 6.2 concurrency: async/await, actors, Sendable and task cancellation.

MIT ★ 233 updated 2026-01-18

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add johnrogers/claude-swift-engineering
/plugin install swift-engineering@claude-swift-engineering
Open on GitHub

What modern-swift does

This skill is about concurrency in Swift 6.2. Data races get caught while the code compiles, so a target that builds under strict checking has none. The skill maps old habits onto new ones: completion handlers become async functions with await, DispatchQueue.main becomes @MainActor, locks become an actor.

Eight reference files live in references/, one each for task groups, cancellation, strict mode, macros, modern attributes and migrating delegate-based code. The skill asks the agent to load them whenever a pattern might apply. A mistakes section names the usual suspects: @unchecked Sendable used to quiet the compiler instead of fixing the cause, missing @MainActor on view models and main test structs, a strong self capture that keeps an object alive for the length of a long task.

Strict concurrency is opt-in via Package.swift. Until the flag is set the compiler won't look for races, so the skill's guarantees cover only the targets where it's on.

What it helps with

  • Move a networking layer off completion handlers onto async/await
  • Switch on strict concurrency in Package.swift and clear Sendable errors
  • Replace a lock around shared mutable state with an actor
  • Fan out parallel work in a TaskGroup and honour cancellation
  • Add @MainActor where view models and test structs touch UI state

Example prompts for the agent

  • Convert this image loader from completion handlers to async/await and mark the view model @MainActor
  • Enable strict concurrency in Package.swift and walk me through each Sendable error
  • Fetch four feeds in parallel with a TaskGroup, and cancel the group when one throws

How to install modern-swift

1Plugin marketplace

/plugin marketplace add johnrogers/claude-swift-engineering
/plugin install swift-engineering@claude-swift-engineering

This installs the whole swift-engineering plugin with all its skills

2Skills CLI (Vercel)

npx skills add johnrogers/claude-swift-engineering --skill modern-swift -a claude-code

3Manually: put the files in place

~/.claude/skills/modern-swift/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/modern-swift/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about modern-swift

How do I install modern-swift in Claude Code?

Add the marketplace with /plugin marketplace add johnrogers/claude-swift-engineering, then install the plugin: /plugin install swift-engineering@claude-swift-engineering.

What does modern-swift do?

It gives the agent Swift 6.2 concurrency patterns: async/await, @MainActor, actor, TaskGroup, cancellation checks. It also covers Sendable errors and shortcuts that backfire, such as reaching for @unchecked Sendable.

What is inside the skill besides the main instructions?

Eight reference files under references/, covering concurrency basics, Swift 6 features, task groups, cancellation, strict mode, macros, modern attributes and migration. The agent is told to load the relevant one as soon as there's a chance it matters.

Source text

SKILL.md · MIT
---
name: modern-swift
description: Use when writing async/await code, enabling strict concurrency, fixing Sendable errors, migrating from completion handlers, managing shared state with actors, or using Task/TaskGroup for concurrency.
---

# Modern Swift (6.2+)

Swift 6.2 introduces strict compile-time concurrency checking with async/await, actors, and Sendable constraints that prevent data races at compile time instead of runtime. This is the foundation of safe concurrent Swift.

## Overview

Modern Swift replaces older concurrency patterns (completion handlers, DispatchQueue, locks) with compiler-enforced safety. The core principle: if it compiles with strict concurrency enabled, it cannot have data races.

## Quick Reference

| Need | Use | NOT |
|------|-----|-----|
| Async operation | `async/await` | Completion handlers |
| Main thread work | `@MainActor` | `DispatchQueue.main` |
| Shared mutable state | `actor` | Locks, serial queues |
| Parallel tasks | `TaskGroup` | `DispatchGroup` |
| Thread safety | `Sendable` | `@unchecked` everywhere |

## Core Workflow

When writing async Swift code:
1. Mark async functions with `async`, call with `await`
2. Apply `@MainActor` to view models and UI-updating code
3. Use `actor` instead of locks for shared mutable state
4. Check `Task.isCancelled` or call `Task.checkCancellation()` in loops
5. Enable strict concurrency in Package.swift for compile-time safety

## Reference Loading Guide

**ALWAYS load reference files if there is even a small chance the content may be required.** It's better to have the context than to miss a pattern or make a mistake.

| Reference | Load When |
|-----------|-----------|
| **[Concurrency Essentials](references/concurrency-essentials.md)** | Writing async code, converting completion handlers, using `await` |
| **[Swift 6 Concurrency](references/swift6-concurrency.md)** | Using `@concurrent`, `nonisolated(unsafe)`, or actor patterns |
| **[Task Groups](references/task-groups.md)** | Running multiple async operations in parallel |
| **[Task Cancellation](references/task-cancellation.md)** | Implementing long-running or cancellable operations |
| **[Strict Concurrency](references/strict-concurrency.md)** | Enabling Swift 6 strict mode or fixing Sendable errors |
| **[Macros](references/macros.md)** | Using or understanding Swift macros like `@Observable` |
| **[Modern Attributes](references/modern-attributes.md)** | Migrating legacy code or using `@preconcurrency`, `@backDeployed` |
| **[Migration Patterns](references/migration-patterns.md)** | Modernizing delegate patterns or UIKit views |

## Common Mistakes

1. **`@unchecked Sendable` as a quick fix** — Using `@unchecked Sendable` to silence compiler errors means you've opted out of safety. If the error persists after `@unchecked`, your code has a potential data race. Fix the underlying issue instead.

2. **Missing `await` at call sites** — Forgetting `await` when calling async functions is a compiler error, but checking `Task.isCancelled` in a loop without calling `Task.checkCancellation()` silently ignores cancellation.

3. **Capturing `self` in async blocks without `weak`** — Holding a strong reference to `self` in a long-running async task prevents deinit. Always use `[weak self]` in closures or use `.task` which auto-manages the lifecycle.

4. **Not checking task cancellation** — Long-running operations should regularly check `Task.isCancelled` or call `Task.checkCancellation()`, otherwise cancellation signals are ignored.

5. **Forgetting `@MainActor` on UI code and test suites** — Main test struct and view models that update `@Published` properties need `@MainActor`. Forgetting it silently allows cross-thread mutations. Apply `@MainActor` to: view models, view structs, main test structs, and any type that touches UI.

6. **Actor re-entrancy surprises** — `await` inside an actor method can release the lock temporarily. Another task may modify actor state. Design actor methods assuming state can change between `await` points.

© John Rogers (@johnrogers) · MIT · johnrogers/claude-swift-engineering

Similar skills

All skills for Programming languages →

From the same set33

The whole set →
foundation-models Gives Claude Code reference patterns for Apple's on-device Foundation Models framework: summarization, extraction, classification. Covers setting up a LanguageModelSession and typed output with @Generable. CX Codex +1 ★ 233repo stars tca-engineer tca-engineer writes the code for a TCA feature from a finished design: reducers, state, actions, dependency clients with test doubles. Views are out of scope. CX Codex ★ 233repo stars sqlite-data Guides database modeling in Swift with the SQLiteData library, macro queries, migrations, and private CloudKit database sync. CX Codex +1 ★ 233repo stars composable-architecture This skill guides feature work with The Composable Architecture (TCA), from reducer structure and effects to navigation and tests. Use it while building or checking TCA features. CX Codex +1 ★ 233repo stars swiftui-patterns swiftui-patterns guides Claude Code through iOS 17+ SwiftUI conventions: the @Observable macro, NavigationStack, and clean UIKit interop. CX Codex +1 ★ 233repo stars swift-testing Get guidance for writing Swift Testing tests, migrating from XCTest, and handling async or parameterized cases in Claude Code. CX Codex +1 ★ 233repo stars tca-architect tca-architect designs feature architectures for The Composable Architecture: State structure, Action taxonomy, dependencies, navigation. Operates in read-only mode. CX Codex ★ 233repo stars swift-architect swift-architect designs Swift feature architecture, file layout, and persistence plans before implementation begins. CX Codex ★ 233repo stars

Project sponsors

Companies that keep this analytics open