modern-swift — скилл для Claude Code: async/await и strict concurrency
Скилл modern-swift для Claude, который ведёт агента при работе с конкурентностью в Swift 6.2: async/await, акторы, Sendable и отмена задач.
MIT ★ 233 обновлён 2026-01-18
/plugin marketplace add johnrogers/claude-swift-engineering
/plugin install swift-engineering@claude-swift-engineeringЧто делает modern-swift
Скилл про конкурентность в Swift 6.2. Компилятор ловит гонки данных на этапе сборки: код, который собирается со strict concurrency, гонок не содержит. Внутри — правила перевода со старых приёмов (completion handlers, DispatchQueue, локи) на async/await, @MainActor и actor, плюс таблица «что использовать вместо чего».
Кроме шпаргалки, скилл велит агенту подгружать восемь справочных файлов из references/ — по TaskGroup, отмене задач, строгому режиму, макросам, миграции делегатов и UIKit. Есть разбор типовых ошибок: @unchecked Sendable вместо починки причины, забытый @MainActor на моделях экрана и главных тестовых структурах, сильная ссылка на self в долгой задаче, которая не даёт объекту освободиться.
Строгая проверка включается флагом в Package.swift. Без неё компилятор не станет искать гонки, так что гарантии скилла действуют только для целей, где режим включён.
Какие задачи решает
- Перевести загрузку данных с completion handlers на async/await
- Включить strict concurrency в
Package.swiftи разобрать ошибки Sendable - Заменить лок на
actorдля общего изменяемого состояния - Запустить параллельные запросы через
TaskGroupс проверкой отмены - Добавить
@MainActorтуда, где тесты и модели экрана трогают UI
Примеры запросов агенту
- Переведи этот сетевой слой с completion handlers на async/await и поставь
@MainActorна модель экрана - Включи strict concurrency в
Package.swiftи пройди по каждой ошибке Sendable - Загрузи четыре ленты параллельно через
TaskGroupи отменяй группу, если одна упала
Как установить modern-swift
1Через маркетплейс плагинов
/plugin marketplace add johnrogers/claude-swift-engineering/plugin install swift-engineering@claude-swift-engineeringКоманда ставит плагин swift-engineering целиком, со всеми его скиллами
2Через Skills CLI (Vercel)
npx skills add johnrogers/claude-swift-engineering --skill modern-swift -a claude-code3Вручную: положить файлы
~/.claude/skills/modern-swift/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/modern-swift/
1Через Skills CLI (Vercel)
npx skills add johnrogers/claude-swift-engineering --skill modern-swift -a codex2Вручную: положить файлы
.agents/skills/modern-swift/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add johnrogers/claude-swift-engineering --skill modern-swift -a cursor2Вручную: положить файлы
.cursor/skills/modern-swift/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install johnrogers/claude-swift-engineering plugins/swift-engineering/skills/modern-swift2Вручную: положить файлы
.github/skills/modern-swift/SKILL.md1Через Skills CLI (Vercel)
npx skills add johnrogers/claude-swift-engineering --skill modern-swift -a gemini-cli2Командой платформы
gemini skills install https://github.com/johnrogers/claude-swift-engineering --path plugins/swift-engineering/skills/modern-swiftВручную: положить файлы
.devin/skills/modern-swift/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Claude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о modern-swift
Как установить modern-swift в Claude Code?
Добавь маркетплейс командой /plugin marketplace add johnrogers/claude-swift-engineering, затем поставь плагин: /plugin install swift-engineering@claude-swift-engineering.
Что делает modern-swift?
Подсказывает агенту, как писать конкурентный код на Swift 6.2: async/await, @MainActor, actor, TaskGroup и проверка отмены. Отдельно разбирает ошибки Sendable и типовые промахи вроде @unchecked Sendable.
Что внутри скилла, кроме основной инструкции?
Восемь справочных файлов в references/: конкурентность, Swift 6, группы задач, отмена, строгий режим, макросы, современные атрибуты и миграция старых паттернов. Скилл велит агенту подгружать нужный файл, как только появляется шанс, что пригодится.
Исходный текст
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