Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add harperreed/dotfiles --skill swiftui-view-refactor -a claude-code
Open on GitHub

What 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 body into smaller view components
  • Inject services and shared models through @Environment or init
  • Store root-level @Observable objects using @State
  • Group helpers and asynchronous functions in private extensions

Example prompts for the agent

  • Refactor this SwiftUI screen using the skill's conventions, reorganize declarations, and preserve its behavior.
  • Split this large body into smaller components and pass each one only the inputs and callbacks it needs.
  • Review how this view initializes its view model and stores its @Observable object, 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-code

2Manually: put the files in place

~/.claude/skills/swiftui-view-refactor/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/swiftui-view-refactor/

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.

From the same set26

uv Guides your AI agent through Python workflows using uv: dependency resolution, virtualenvs, PEP 723 scripts, CI, and multistage Docker builds. CX Codex +1 ★ 336repo stars session-reflection-analysis Analyzes Claude Code conversation history to uncover workflow friction and curb token usage. Ideal for running retrospectives after long coding sessions. CX Codex +1 ★ 336repo stars releasing-software This skill walks through release checks, from builds and tests to CI and tagging. Use it to hold off on a tag until CI succeeds. CX Codex +1 ★ 336repo stars native-app-performance A skill that profiles native macOS and iOS apps with xctrace and Time Profiler. Instruments traces get analyzed from the terminal, no Instruments UI needed. CX Codex +1 ★ 336repo stars ios-debugger-agent Controls a booted iOS simulator via XcodeBuildMCP to build schemes and inspect on-screen UI elements. CX Codex +1 ★ 336repo stars humanizer This skill spots common AI-writing patterns and rewrites them while preserving the text’s meaning and intended tone. Use it to revise drafts or review finished copy. CX Codex +1 ★ 336repo stars summarize-meetings A skill that reads meeting transcripts in an Obsidian vault, pulls out people, action items and ideas, then writes summary files and links between notes. CX Codex +1 ★ 336repo stars strategy-diagnosis Runs structured diagnostic frameworks to help founders and operators dissect tough business problems step by step. CX Codex +1 ★ 336repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor