Command Palette

Search for a command to run...

Назад к скиллам
скилл № 08219

write-swift

How to write modern Swift well — modeling with value types, Swift 6 data-race safety and approachable concurrency (@concurrent, main-actor-by-default, actors…

БесплатноБез исполняемых скриптов
Asymmetric-alот Asymmetric-al★ 354 звезды на GitHub

Установить write-swift в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Write Swift

This repository (Asymmetric-al/core)

This skill is Swift craft guidance. Core's product apps are Next.js and do not use Swift. Reconcile this overlay after upstream refreshes before running bun run skills:sync.

Triggers

  • Explicit Swift, SwiftUI, or Apple-platform language work.
  • Keep disable-model-invocation: true. Do not load it for Core web/TypeScript hangs, data races, or performance work.

Workflow

  1. Confirm the request is actually Swift before applying this file.
  2. For Core Next.js apps, use docs/ai/rules/frontend.md and the matching TypeScript/React skills instead.

Checklist

  • The target language is Swift, not Core's TypeScript apps.

When invoked without a concrete task, briefly ask for the objective. If a task or question is already present, continue its workflow immediately.

How to write Swift the way the language wants to be written, current through Swift 6.4.

Toolchain baseline: Swift 6.4 (current public release). Rows and notes marked ⚠ require Swift 6.4; keep the older form when the project toolchain is Swift 6.3 or earlier. Concurrency guidance assumes the Swift 6.2 model — if the project is on 6.1 or earlier, §3's rules about async and @concurrent do not apply.

The through-line: Swift is a progressive-disclosure language. Start with the simplest, most static, most single-threaded thing that works, and buy dynamism — concurrency, reference semantics, existentials, unsafe pointers — only where you can point at the reason. Every rule below is an application of that.

Model this hierarchy of defaults. Move down a level only with a reason you can state:

Need Reach for Move down only when
Data struct / enum you need identity, sharing, or inheritance
Abstraction concrete type you have repeated code across types
Polymorphism some P (generic) you need heterogeneous storage → any P
Execution main actor, synchronous profiling shows a hang → async → @concurrent → actor
Memory Array, String profiling shows the cost → InlineArray, Span
Safety safe API C interop or a measured hot path → Unsafe*

1. Model data with value types

Value types are the default in Swift, not a special case.

  • Default to struct and enum. Use class only for identity, shared mutable state, inheritance, or resource lifetime. A window, a database connection, an entity stored in a rendering engine — those have identity. A Point, a Drink, a Material does not.
  • let by default; var only when you mutate. This is the same discipline as some before any and value before reference: start narrow, widen with cause.
  • A struct with a mutable reference-type property is neither a value nor a reference. Copies share the object; mutations leak across copies. Either keep the referenced type immutable, or make it a private stored property behind copy-on-write. Computed properties that forward to it don't help on their own: a forwarding setter still mutates the shared object.
  • Copy-on-write is how you get out-of-line storage and value semantics. Wrap a final class in a struct and check isKnownUniquelyReferenced(&storage) before mutating; copy first if it isn't. This is exactly how Array, String, and Dictionary work.
  • Enums are the tool for "a fixed set of things" and for mutually exclusive state. Replacing a pile of optional stored properties (isSharing, selectedRows, shareTarget) with one enum State makes invalid combinations unrepresentable and makes state change atomic instead of a sequence of property writes you can forget to finish.
  • Composing values yields a value. A struct whose stored properties are all value types has value semantics for free — which is what makes undo, diffing, and state restoration a single code path instead of one per property.
struct Material {                       // value semantics preserved
  var roughness: Double
  private var _texture: Texture         // a class

  var color: Color {
    get { _texture.color }
    set {
      if !isKnownUniquelyReferenced(&_texture) { _texture = Texture(copying: _texture) }
      _texture.color = newValue
    }
  }
}

Noncopyable types (~Copyable) express unique ownership: a file descriptor, a bank transfer, an open resource. Suppressing the copy turns "you must not run this twice" from an assertion into a compile error, and makes deinit on a struct meaningful. Mark the finishing method consuming so the compiler proves it's the last use. Parameter ownership becomes explicit: `b

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • agents/openai.yaml
  • references/LICENSE.md
  • references/upstream.md

FAQ

Что делает скилл write-swift?

How to write modern Swift well — modeling with value types, Swift 6 data-race safety and approachable concurrency (@concurrent, main-actor-by-default, actors, task groups), protocols and generics (some vs any), API design, performance and ARC, Swift Testing, macros, and the modern language features agents don't know about yet. Use when writing, reviewing, or migrating Swift. Only runs when explicitly invoked; it does not trigger on its own.

Как установить скилл write-swift?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл write-swift запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить write-swift с