write-swift

Guides writing, reviewing, and migrating modern Swift code through Swift 6.4.

Updated Sep 5, 2023
One-click install
npx skills add https://github.com/eyenalxai/dotfiles --skill write-swift-eyenalxai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-swift
Source: https://github.com/eyenalxai/dotfiles/tree/main/.agents/skills/write-swift
Command: npx skills add https://github.com/eyenalxai/dotfiles --skill write-swift-eyenalxai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Swift's concurrency model, ownership rules, and performance characteristics changed significantly in Swift 6.x, and outdated habits cause data races, hangs, retain cycles, and slow code. This Skill provides current, opinionated guidance so generated or reviewed Swift follows the language's intended design. ## Core Features & Use Cases - Modern Swift 6 Concurrency: Covers the Swift 6.2 model where async stays on the caller's actor, plus @concurrent, actors, task groups, Sendable, and main-actor-by-default settings. - Idiomatic Design Guidance: Value-type modeling, copy-on-write, some vs any, protocol design, error handling, ARC and lifetime rules, and API design principles. - Performance, Testing, and Tooling: Profiling-driven optimization with InlineArray and Span, Swift Testing with @Test and #expect, macros, and structured logging. - Use Case: When a Swift 6 migration produces a data-race compiler error, use this Skill to work down the fix ladder — stop sharing the value, make it a Sendable value type, isolate it to an actor, or synchronize it — instead of silencing the warning. ## Quick Start Review this Swift file and fix any data-race safety issues using modern Swift 6 concurrency patterns.

Frequently Asked Questions about write-swift

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

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

Work down a priority 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 at step one.

What changed about async functions in Swift 6.2?

In Swift 6.2, marking a function async no longer moves it off the current actor; it runs where it was called from. Use @concurrent to guarantee background execution for CPU-heavy work and nonisolated for library APIs where the caller decides isolation.

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

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

When should I use Swift Testing instead of XCTest?

Use Swift Testing for all new tests since @Test, #expect, and parameterized arguments cover most needs. XCTest remains required only for UI automation with XCUIApplication, performance metrics with XCTMetric, and Objective-C exception testing.

Why does my Swift actor code still have race conditions?

Actors guarantee mutual exclusion, not transactions, so state can change between awaits on the same actor. Mutate actor state in synchronous methods, keep async methods thin, and re-check assumptions after every await to avoid check-then-act bugs.

When should Swift code avoid using concurrency at all?

Start single-threaded on the main actor and add concurrency only after profiling shows a hang. Spawning tasks for trivial work costs more than it saves, and async functions carry real scheduling overhead, so synchronous code is the correct default.