swiftui-view-refactor · harperreed — Claude Code skill for SwiftUI refactoring
This skill guides SwiftUI view cleanup, dependency injection, and Observation state handling. Use it when reorganizing existing screens or reviewing view architecture.
npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a claude-codeWhat swiftui-view-refactor does
The skill defines a consistent order for SwiftUI view declarations: environment values and stored properties first, followed by computed non-view values, initialization, body, and supporting view builders or functions. Large screen bodies should be divided into smaller components, with each receiving only the data, bindings, and callbacks it needs. The goal is to keep view code readable without adding unnecessary architectural layers.
Its default direction is Model-View. Business rules belong in models and services, while views coordinate state with @State, @Environment, @Query, task, and onChange. Root views should hold @Observable reference objects in @State. When a view already has a view model, initialize it with dependencies passed through init and avoid optional storage where the design allows it.
Files longer than roughly 300 lines can be organized with private extensions and purpose-specific // MARK: - sections. The refactor should preserve existing behavior unless the request calls for a functional change. This matters when extracting subviews: changing the structure should not silently alter the screen's layout or business rules.
What it helps with
- Standardize the declaration order in a SwiftUI view
- Break a large
bodyinto smaller view components - Inject services and shared models through
@Environmentorinit - Store root-level
@Observableobjects using@State - Group helpers and asynchronous functions in
privateextensions
Example prompts for the agent
- Refactor this SwiftUI screen using the skill's conventions, reorganize declarations, and preserve its behavior.
- Split this large
bodyinto smaller components and pass each one only the inputs and callbacks it needs. - Review how this view initializes its view model and stores its
@Observableobject, then align it with the Model-View approach.
How to install swiftui-view-refactor
1Skills CLI (Vercel)
npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a claude-code2Manually: put the files in place
~/.claude/skills/swiftui-view-refactor/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/swiftui-view-refactor/
1Skills CLI (Vercel)
npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a codex2Manually: put the files in place
.agents/skills/swiftui-view-refactor/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a cursor2Manually: put the files in place
.cursor/skills/swiftui-view-refactor/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install harperreed/dotfiles swiftui-view-refactor2Manually: put the files in place
.github/skills/swiftui-view-refactor/SKILL.md1Skills CLI (Vercel)
npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a gemini-cli2Platform CLI
gemini skills install https://github.com/harperreed/dotfiles --path .claude/skills/swiftui-view-refactorManually: put the files in place
.devin/skills/swiftui-view-refactor/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about swiftui-view-refactor
How do I install swiftui-view-refactor in Claude Code?
Run npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a claude-code. The installed instructions are located at ~/.claude/skills/swiftui-view-refactor/SKILL.md.
What does swiftui-view-refactor do?
It provides conventions for organizing SwiftUI views, extracting smaller components, injecting dependencies, and managing Observation state. Existing behavior should remain unchanged unless a functional modification is requested.
Should I create a view model for every SwiftUI screen?
No. The skill favors lightweight views and recommends introducing a view model only when the request or existing code calls for one. If a view model is already present, initialize it with injected dependencies and use non-optional state when practical.
Similar skills
All skills for Frontend and UI →swiftui-view-refactor by other authors comes first.