Swift
Writes, debugs, and optimizes Swift — concurrency, ARC leaks, optionals, generics, SwiftUI state, and packages. Use when writing or reviewing Swift code, when…
от clawic★ 23 звезды на GitHub
Установить Swift в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
User preferences and memory live in ~/Clawic/data/swift/ (see setup.md on first use, memory-template.md for the file format). If you have data at an old location (~/swift/ or ~/clawic/swift/), move it to ~/Clawic/data/swift/, and say in one line that you moved it and from where.
When To Use
- Writing, reviewing, or refactoring Swift: models, protocols, generics, async code, SwiftUI views, packages
- Diagnosing a crash from its message, or a hang with no message: nil unwrap, arithmetic overflow, unowned dangling, exclusivity violation, continuation never resumed
- Fixing Swift 6 data-race errors,
Sendableconformance failures, and actor-isolation diagnostics during a language-mode migration - Chasing memory: retain cycles, objects that never
deinit, growth Instruments blames on nothing - Making builds and binaries faster: type-check blowups, generic bloat, ARC traffic, existential boxing
- Shipping Swift off Apple platforms: Linux and server builds, static linking, Foundation gaps, C interop
- Not for Xcode project settings, signing, or provisioning (→
xcode), and not for App Store review, app lifecycle, or platform frameworks (→ios)
Quick Reference
| Situation | Play |
|---|---|
| Crash with a Swift message ("Unexpectedly found nil", "Index out of range") | Decode it in Crash Messages below, then debugging.md for the chain |
| Crash with no message (EXC_BAD_ACCESS, bare SIGTRAP) | Memory Graph, zombies, then sanitizers → debugging.md |
Object never deallocates, deinit never runs |
Retain cycle: closure, delegate, timer, or observer → arc.md |
| "Sending value of non-Sendable type", "actor-isolated property" | concurrency.md for the rule, swift6-migration.md for the order to fix them in |
| Async code hangs with no error and no CPU | Continuation never resumed, or a blocked cooperative thread (rule 4) → concurrency.md |
| Upgrading a codebase to Swift 6 language mode | Per-target ratchet, not a big bang → swift6-migration.md |
Too many !, try!, or IUOs; nil handling is noisy |
optionals.md |
Designing the failure channel: throws vs Result vs optional, typed throws, retry, cancellation |
errors.md |
| JSON decode throws, keys missing, dates rejected | codable.md (fractional-second ISO 8601 is the usual one) |
any vs some vs generic; a protocol default never gets called |
types.md |
| Unicode, string indices, substrings, regex, locale-sensitive compare | strings.md |
| Array/Dictionary/Set behavior, ordering, or an O(n²) blowup | collections.md |
| Arithmetic traps at runtime, a numeric conversion crashes, floats compare wrong, or money needs a type | numerics.md |
| SwiftUI state resets, views redraw constantly, layout fights back | swiftui.md |
| Tests flaky, async tests pass before the work finishes | testing.md |
| Package won't resolve, resources missing, plugin blocked | packages.md |
| Slow build, slow runtime, oversized binary | performance.md |
| Objective-C, C, or C++ bridging; unsafe pointers; C callbacks | interop.md |
| Builds on macOS, fails on Linux or in a container | linux.md |
| Designing public API: naming, access control, availability, ABI | api-design.md |
| Property wrappers, result builders, macros, key paths | metaprogramming.md |
| Anything else | Reduce to the smallest file that still reproduces, compile with -Onone, and read the FIRST compiler error — the rest is usually cascade noise |
Core Rules
!is a deliberate crash, not a shortcut. Recoverable nil →guard let x else { return }. Nil that means the program is already broken →guard let x else { fatalError("config missing: \(key)") }; the crash log then names the invariant instead of "Unexpectedly found nil while unwrapping an Optional value", which names nothing. Only IBOutlets and two-phase init justify an implicitly unwrappedT!.weakwhen the target can die first;unownedonly when lifetimes are provably nested. Test: can the referenced object deallocate while this reference exists? Yes →weak(becomes nil, no crash). Provably no, because it owns me →unowned(one less check, but a dangling read is an immediate crash rather than a nil). Escaping closures that touchself:[weak self] in guard let self else { return }. Non-escaping closures (map,forEach,withLock) never need a capture list — they cannot outlive the call.- Reference type only for identity or lifecycle. Default
struct. Reach forclass/actorwhen the thing has identity (two copies with equal fields are still different things), needsdeinit, or is genuinely shared and mutated in place. Copy cost is not the tiebreaker: standard-library collections are copy-on-write, so a copy is a retain until someone writes (→types.md). - Never block a thread in the cooperative pool. Swift concurrency runs one thread per active core, so on an 8-core machine 8 concurrent
DispatchSemaphore.wait()calls insideasyncf
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- _meta.json
- api-design.md
- arc.md
- codable.md
- collections.md
- concurrency.md
- debugging.md
- errors.md
- interop.md
- linux.md
- memory-template.md
- metaprogramming.md
- numerics.md
- optionals.md
- packages.md
- performance.md
- setup.md
- strings.md
- swift6-migration.md
- swiftui.md
- testing.md
- types.md
FAQ
Что делает скилл Swift?
Writes, debugs, and optimizes Swift — concurrency, ARC leaks, optionals, generics, SwiftUI state, and packages. Use when writing or reviewing Swift code, when a build won't type-check or the compiler "is unable to type-check this expression in reasonable time", when an app crashes on a force unwrap, an unowned reference, or EXC_BAD_ACCESS, when Swift 6 raises Sendable / actor-isolated / data-race errors, when a retain cycle keeps objects alive, when JSON fails to decode, when async code hangs or deadlocks, when SwiftUI state resets or views redraw too often, when XCTest or Swift Testing tests are flaky, when a Swift package won't resolve, or when bridging to Objective-C, C, or Linux. Not for Xcode signing and IDE settings, or App Store submission and iOS app lifecycle.
Как установить скилл Swift?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Swift запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…