modern-swift
БесплатноБез исполняемых скриптовНе проверенUse when writing async/await code, enabling strict concurrency, fixing Sendable errors, migrating from completion handlers, managing shared state with actors…
Об этом скилле
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:
- Mark async functions with
async, call withawait - Apply
@MainActorto view models and UI-updating code - Use
actorinstead of locks for shared mutable state - Check
Task.isCancelledor callTask.checkCancellation()in loops - 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 | Writing async code, converting completion handlers, using await |
| Swift 6 Concurrency | Using @concurrent, nonisolated(unsafe), or actor patterns |
| Task Groups | Running multiple async operations in parallel |
| Task Cancellation | Implementing long-running or cancellable operations |
| Strict Concurrency | Enabling Swift 6 strict mode or fixing Sendable errors |
| Macros | Using or understanding Swift macros like @Observable |
| Modern Attributes | Migrating legacy code or using @preconcurrency, @backDeployed |
| Migration Patterns | Modernizing delegate patterns or UIKit views |
Common Mistakes
@unchecked Sendableas a quick fix — Using@unchecked Sendableto 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.Missing
awaitat call sites — Forgettingawaitwhen calling async functions is a compiler error, but checkingTask.isCancelledin a loop without callingTask.checkCancellation()silently ignores cancellation.Capturing
selfin async blocks withoutweak— Holding a strong reference toselfin a long-running async task prevents deinit. Always use[weak self]in closures or use.taskwhich auto-manages the lifecycle.Not checking task cancellation — Long-running operations should regularly check
Task.isCancelledor callTask.checkCancellation(), otherwise cancellation signals are ignored.Forgetting
@MainActoron UI code and test suites — Main test struct and view models that update@Publishedproperties need@MainActor. Forgetting it silently allows cross-thread mutations. Apply@MainActorto: view models, view structs, main test structs, and any type that touches UI.Actor re-entrancy surprises —
awaitinside an actor method can release the lock temporarily. Another task may modify actor state. Design actor methods assuming state can change betweenawaitpoints.
Установить modern-swift в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл modern-swift?
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?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл modern-swift запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic