swiftui-expert-skill

Reviews, refactors, and implements SwiftUI code with API migration guidance and Instruments trace analysis.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Writing correct, performant SwiftUI code requires keeping up with rapidly evolving APIs, state management rules, and deprecation cycles across iOS and macOS versions. This Skill provides structured guidance for reviewing, improving, and implementing SwiftUI code, plus workflows for recording and analyzing Instruments traces to diagnose performance issues. ## Core Features & Use Cases - Code Review and Refactoring: Audits SwiftUI code against a correctness checklist covering @State privacy, ForEach identity, @Observable data flow, and animation patterns, replacing hard-deprecated APIs with modern equivalents. - Topic-Routed References: Routes each task to one of 30+ focused reference files covering state management, lists, layout, animations, charts, accessibility, macOS scenes, document-based apps, and Liquid Glass. - Instruments Trace Workflows: Records .trace files via xctrace with device-aware template selection, then analyzes time profiler, hangs, hitches, and SwiftUI update causes to produce prioritized optimization plans. - Use Case: A developer notices scroll stutter in their SwiftUI app. They record a trace, run the analysis script to find that a wide EnvironmentWriter is invalidating dozens of views, and receive a targeted fix recommendation grounded in the state-management reference. ## Quick Start Ask the assistant to review your SwiftUI view file for correctness and performance issues using the SwiftUI expert skill.

Frequently Asked Questions about swiftui-expert-skill

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

FAQPage Schema
How do I review SwiftUI code for performance issues?▼

Audit the code against the correctness checklist: verify @State is private, ForEach uses stable identity, and animations use the value parameter. Then consult the performance-patterns reference to reduce unnecessary state updates and extract complex view bodies into subviews.

How to analyze an Instruments .trace file for SwiftUI problems?▼

Run the analyze_trace.py script with --json-only to get time profiler, hangs, hitches, and SwiftUI lanes plus cross-lane correlations. Check main_running_coverage_pct and swiftui-causes top sources to find which views are invalidated and why.

Should I use @StateObject or @ObservedObject in SwiftUI?▼

Use @StateObject when the view owns and creates the object, and @ObservedObject when the object is injected from a parent. On iOS 17+, prefer @State with @Observable classes and @Bindable for injected observables that need bindings.

Does SwiftUI trace recording work on the iOS Simulator?▼

The SwiftUI Instruments template returns an empty SwiftUI lane on the iOS Simulator. Use the Time Profiler template instead, which still captures Time Profiler, Hangs, and Animation Hitches data; the SwiftUI template works on physical devices and the host Mac.

When should I migrate from FileDocument to the new Document API?▼

The Document protocol family replaces FileDocument on iOS 27, macOS 27, and visionOS 27. For earlier deployment targets, keep FileDocument since it is only soft-deprecated; migrate by converting to an @Observable class with DocumentReader and DocumentWriter.

Why does my SwiftUI animation not fire on view removal?▼

Transitions require an animation context outside the conditional. Placing .animation inside the if-branch removes it with the view, so removal transitions never animate; wrap the state change in withAnimation or place .animation(_:value:) on the parent.