write-swift

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

2|Updated Sep 8, 2026
One-click install
npx skills add https://github.com/hanshi-notes/hanshi --skill write-swift-hanshi-notes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: write-swift
Source: https://github.com/hanshi-notes/hanshi/tree/main/.agents/skills/write-swift
Command: npx skills add https://github.com/hanshi-notes/hanshi --skill write-swift-hanshi-notes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Swift's concurrency model changed significantly in Swift 6.2, and most guidance and training data still reflects outdated patterns, leading to data races, hangs, retain cycles, and misused actors. This Skill provides current, opinionated rules for writing Swift the way the language intends, from value-type modeling through structured concurrency, testing, and performance tuning. ## Core Features & Use Cases - Swift 6 Concurrency Guidance: Covers the main-actor-by-default model, @concurrent, actors, Sendable checking, task groups, and a step-by-step fix list for data-race errors. - Idiomatic Language Patterns: Rules for structs vs classes, some vs any, typed throws, copy-on-write, noncopyable types, macros, and API design grounded in clarity at the point of use. - Performance and Testing Practices: Profiling-driven optimization with Instruments, ARC and lifetime rules, and Swift Testing patterns including parameterized tests and traits. - Use Case: When a SwiftUI app hangs or the compiler reports a sendability error after migrating to Swift 6, use this Skill to diagnose whether the fix is removing sharing, isolating to an actor, or restructuring the async code. ## Quick Start Ask the assistant to review your Swift file for Swift 6 concurrency correctness and suggest fixes for any data-race or actor-isolation errors.

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 fixed 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.

When should I use an actor vs @concurrent in Swift?▼

Use @concurrent to move your own CPU-heavy work off the main thread after profiling shows a hang. Use an actor only when you need to move mutable state off the main actor because tasks are hopping back constantly. Start single-threaded and add concurrency only with a measured reason.

What is the difference between some and any in Swift?▼

some P keeps one fixed underlying type per scope, preserving associated-type relationships and enabling compiler specialization. any P is a type-erased box for heterogeneous storage, but it erases associated types and blocks optimization. Default to some and switch to any only when you need heterogeneous collections.

Does marking a function async move it off the main actor in Swift 6?▼

No. Since Swift 6.2, an async function runs on the caller's actor by default. To guarantee background execution you must mark it @concurrent, and nonisolated makes it run wherever it is called from, which is the right default for library APIs.

Should I use Swift Testing or XCTest for new tests?▼

Use Swift Testing for new tests: @Test functions, #expect expressions, parameterized arguments, and trait-based filtering. XCTest remains required only for UI automation with XCUIApplication, performance metrics with XCTMetric, and Objective-C exception testing.

Why does my Swift code hang or deadlock with actors?▼

Actors guarantee mutual exclusion, not transactions, and they are not FIFO. A common bug is checking state, awaiting, then writing, which lets two tasks interleave. Mutate actor state in synchronous methods and re-check assumptions after every await.