Skip to content

SwiftUI View Refactor

Restructures SwiftUI views for clear ordering, MV patterns, and correct Observation usage

Stars
7,433
Licence
MIT
Files
2 files

What it does

When installed, the agent follows a set of conventions when reviewing or refactoring SwiftUI code: it orders the parts of a view consistently, splits large view bodies into smaller subviews, favors built-in state tools like @State and @Environment over adding view model classes, and checks that observable objects are stored correctly. It is guidance only; the files contain no scripts and no network calls.

Great for

  • iOS or macOS developers who want SwiftUI views cleaned up without changing behavior
  • Teams that want a consistent MV-style (Model-View) structure instead of view model classes
  • Reviewers checking SwiftUI code for Observation misuse such as unnecessary optional state

Skip it if

  • Projects that deliberately use MVVM with view models and want those replaced: the skill tells the agent to avoid introducing view models, which may conflict with an existing architecture
  • Non-SwiftUI UI code (UIKit, AppKit, web), where the rules do not apply

Try asking

  • “Refactor this SwiftUI view so the body is ordered per our conventions, keeping behavior the same”
  • “Review my SwiftUI screen for Observation problems and split the long body into subviews”
  • “Convert the optional view model in this SwiftUI view to a non-optional @State initialized in init”
Step-by-step guide: how to use SwiftUI View RefactorInstall, first run, examples, tips and FAQs

Install in 3 steps

  1. 1

    Download the skill

    The ZIP contains the 2 original files, the MIT licence and an attribution note.

    swiftui-view-refactor.zip
  2. 2

    Add it to your agent

    Claude Code (all projects)

    mkdir -p ~/.claude/skills && unzip swiftui-view-refactor.zip -d ~/.claude/skills/

    Claude Code / Agent SDK (this project only)

    mkdir -p .claude/skills && unzip swiftui-view-refactor.zip -d .claude/skills/

    Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.

  3. 3

    Ask for the task

    No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.

Get better results

  • Point the agent at a specific file and state whether your project already uses view models, since the skill only changes them when they already exist
  • Ask for a behavior-preserving refactor and build the project afterward to confirm nothing broke
  • Review the diff yourself, because reordering and extracting subviews can still introduce subtle changes

What's inside

  • references/mv-patterns.md
  • SKILL.md

Redistributed unmodified from steipete/agent-scripts under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.