write-swift

Guides writing, reviewing, and migrating modern Swift code with Swift 6 concurrency and value-type modeling.

34.1k|1.9k|Updated Mar 16, 2026
One-click install
npx skills add https://github.com/emilkowalski/skills --skill write-swift
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-swift
Source: https://github.com/emilkowalski/skills/tree/main/skills/write-swift
Command: npx skills add https://github.com/emilkowalski/skills --skill write-swift

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Swift's concurrency model changed significantly in Swift 6.2, and most code generators and developers still write outdated patterns — unnecessary actors, misused async, data races, retain cycles, and protocol over-engineering. This Skill encodes current best practices through Swift 6.3/6.4 so Swift code is written the way the language intends.

Core Features & Use Cases

  • Modern Concurrency Guidance: Covers the Swift 6.2 model — main-actor-by-default, @concurrent, nonisolated, actors, structured concurrency, and a step-by-step fix list for data-race errors.
  • Value-Type Data Modeling: Enforces struct/enum-first design, copy-on-write, noncopyable types, and some vs any existential decisions.
  • Performance, ARC, and Testing: Details profiling-driven optimization (InlineArray, Span, existential buffers), reference-cycle elimination, and Swift Testing with @Test, #expect, and parameterized suites.
  • Use Case: When migrating a codebase to Swift 6 strict concurrency and hitting sendability errors, use this Skill to work down the fix list — don't share, make it a Sendable value type, isolate to an actor, then reach for Mutex.

Quick Start

Review my Swift package for Swift 6 concurrency issues and rewrite the networking layer using approachable concurrency with main-actor default isolation.

Frequently Asked Questions about write-swift

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Swift 6 data-race and Sendable errors?

Work down a prioritized list: first stop sharing the object by giving each concurrent job its own instance, then make it a Sendable value type, then isolate it to an actor, and only as a last resort use Mutex, Atomics, or @unchecked Sendable. Most real errors are fixed by the first step.

How does Swift 6.2 concurrency differ from earlier versions?

In Swift 6.2, marking a function async no longer moves it off the current actor — it runs where it was called. Use @concurrent to move CPU-heavy work to the background thread pool and nonisolated for library APIs so callers decide where work runs.

When should I use an actor in Swift?

Use an actor only to move state off the main actor when too much main-actor state forces constant task hopping. Start single-threaded, add async/await for latency, then @concurrent for CPU work, and actors last — actors guarantee mutual exclusion, not transactions or FIFO ordering.

Should I use some or any for protocol types in Swift?

Write some P by default since it preserves associated-type relationships and lets the compiler specialize. Switch to any P only when you need heterogeneous storage or optionality of the underlying type, accepting type erasure and opaque dispatch costs.

When should I use Swift Testing instead of XCTest?

Use Swift Testing for all new tests — it supports @Test on any function, #expect with ordinary expressions, parameterized arguments, and parallel execution by default. XCTest remains required only for UI automation, performance metrics, and Objective-C exception tests.

Why does my Swift code have retain cycles and how do I fix them?

Retain cycles come from strong reference loops between objects. Prefer restructuring over weak references: factor shared data into a third type both sides reference, turning the cycle into a tree, since weak reads after the owner's last use can silently return nil.