/mobile:code-swiftfrom mobile
How to write good Swift and SwiftUI beyond the iOS rules - view identity and diffing, concurrency and actor isolation, Sendable, value semantics, memory, and the traps at the Kotlin (KMP) boundary. Use when writing or reviewing Swift. The iOS rules decide how the app is shaped; if they and this skill disagree, the rule wins and you say so.
Ships in mobile. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The iOS rules are the baseline (no force unwraps, no try? on user actions, tokens, modern SwiftUI). This is the
depth beyond them. If a rule and this skill disagree, the rule wins: say so.
Most "SwiftUI is doing something weird" is an identity problem.
if a { Foo() } else { Foo() } makes two different
views: their state resets when a flips. Foo().opacity(a ? 1 : 0) is one view that keeps its state. That is why
a ternary inside a modifier beats an if/else around the view..id() and ForEach's key. .id(changingValue) destroys and rebuilds the view:
@State resets and .task runs again. Useful on purpose, a performance cliff by accident.ForEach over indices is a bug once the list can reorder or delete. Key on a stable id.@ViewBuilder over AnyView. AnyView hides the type, and the type is how SwiftUI knows two renders are the
same view.containerRelativeFrame sizes to the safe area even under .ignoresSafeArea(). A full-bleed image goes in
Color.clear.overlay { image }.ignoresSafeArea().DragGesture on a horizontal carousel inside a vertical ScrollView takes the page's scroll. Use a
UIKit pan (UIGestureRecognizerRepresentable) that only begins on a mostly sideways drag; keep the SwiftUI drag for
older versions.@MainActor is inherited. SwiftUI views are on the main actor, so a Task { } inside one already runs there.
A delegate callback is not, which is why location and camera callbacks need MainActor.assumeIsolated.assumeIsolated asserts, it doesn't switch. Use it only when you know you're on the main thread: if you're
wrong, it crashes. When unsure, await MainActor.run.isOn ? delete : nil) is @MainActor and doesn't convert to a plain
closure type there; the compiler only says "failed to produce diagnostic" on the whole body. Wrap it:
{ delete($0) }.Task { } inherits the actor and priority; Task.detached { } inherits neither. Detached is almost always
wrong..task { } is cancelled when the view goes away; a Task started in onAppear is not. A stored Task you
must remember to cancel is a leak with a manual step.Sendable is a promise about crossing actors. A final class with only let properties is Sendable;
anything with var needs an actor or a lock, and an @unchecked Sendable you can defend in review.actor serialises access, it doesn't make code fast. Every await on it can suspend: what you read before
the await may have changed after it. Check again.struct by default; class when identity matters or a framework needs it. "It's big" is not a reason: the
standard collections copy lazily.let array of structs is fully immutable; a let array of classes is not, and you can't see the difference
at the call site. Prefer structs for anything crossing a boundary.@Observable over ObservableObject for Swift-side state: views re-render only for the properties they read.
Shared Kotlin ViewModels use @StateViewModel, which is a different mechanism.guard let for the early exit, if let for a short branch. A guard whose else is longer than two lines wanted
to be an if let.enum: Error, so the caller can switch on it.Result stores an outcome; throws passes one along. Convert once, where the outcome is stored.[weak self] only in a closure that the captured object stores. A closure passed to map doesn't need it.[weak self] + guard let self else { return } is the idiom.Task stored in @State keeps its captures alive until it finishes or is cancelled: another reason to use
.task.default:. A default: lets a new Kotlin case
compile on iOS and silently do nothing.NSObject member (description, hash) arrives renamed with a trailing
_: read product.description_. Plain .description compiles and shows the whole object's debug text. Some
(zone) aren't renamed and can't be read at all: name a shared contract's fields away from NSObject's.Date: convert them in one extension, never inline.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
4 skills in this plugin
/code-kotlinHow to write good Kotlin beyond the KMP rules - structured concurrency, choosing Flow operators, sealed types and value classes, serialization edge cases, and the traps of Kotlin Multiplatform on iOS. Use when writing or reviewing Kotlin. The KMP rules decide how the app is shaped; if they and this skill disagree, the rule wins and you say so./code-swiftuiComprehensively reviews SwiftUI code for best practices on modern APIs, maintainability, and performance. Use when reading, writing, or reviewing SwiftUI projects./mobile-app-ui-designDesign high-quality mobile app UI/UX screens, flows, and components. Use this skill whenever the user asks to design a mobile app screen, create app mockups, build mobile UI components, improve an existing mobile app design, create onboarding flows, design mobile navigation, or requests any mobile-first interface work. Also trigger when the user mentions app design, mobile UI, mobile UX, screen design, app mockups, wireframes, or wants to build React Native / Flutter / SwiftUI style interfaces as visual prototypes. Even if the user just says "design an app" or "make this screen look better", use this skill.npx claudepluginhub fractalx-technologies/claude-config --plugin mobile