swiftui-view-refactor

Refactors SwiftUI view files by splitting oversized views and removing inline side effects.

Updated Feb 8, 2026
One-click install
npx skills add https://github.com/irchamaji/agents --skill swiftui-view-refactor-irchamaji
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/irchamaji/agents/tree/main/skills/swiftui-view-refactor
Command: npx skills add https://github.com/irchamaji/agents --skill swiftui-view-refactor-irchamaji

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It reduces brittle, sprawling SwiftUI view files by enforcing a stable view tree, extracting meaningful subviews, and keeping business logic out of the view body while standardizing Observation and dependency injection patterns.

Core Features & Use Cases

  • Stable, readable view structure: Reorders Environment, stored properties, init, body, and helper builders so the file reads top-to-bottom as data flow plus UI.
  • MV-first guidance (not MVVM by default): Prefers @State, @Environment, and lightweight orchestration via .task / onChange before introducing a view model.
  • Subview extraction over computed some View: Flags overly long bodies and large helper fragments and replaces them with dedicated View types that take explicit inputs.
  • Move side effects and actions out of body: Keeps the body declarative by routing non-trivial actions and async work into small private methods and services/models.
  • Correct Observation usage: Standardizes how @Observable reference types are owned and passed to avoid churn and unnecessary optional patterns.
  • Use Case: When cleaning up a large SwiftUI screen, split it into focused subviews, remove inline button actions and hidden logic in modifiers, and ensure the view identity stays stable.

Quick Start

Use swiftui-view-refactor to clean up and split the current SwiftUI view file while preserving behavior, improving structure, and applying MV-first + Observation-safe defaults.

Frequently Asked Questions about swiftui-view-refactor

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

FAQPage Schema
How do I refactor a SwiftUI view with a long body into subviews?▼

To refactor a SwiftUI view with a long body, extract large fragments into dedicated `View` types that take explicit inputs, replacing computed `some View` properties to ensure a stable view tree and improve maintainability.

Why does my SwiftUI view tree rebuild when using @Observable?▼

Your SwiftUI view tree may rebuild unnecessarily due to incorrect `@Observable` ownership and initialization patterns. Standardizing how reference types are owned and passed avoids churn and eliminates unnecessary optional patterns.

What is the best way to remove side effects from a SwiftUI view body?▼

The best way to remove side effects from a SwiftUI view body is to route non-trivial inline button actions and async work into small private methods, services, or models, keeping the body strictly declarative.

Does this refactoring approach use MVVM by default for SwiftUI?▼

This refactoring approach does not use MVVM by default. It applies an MV-first structure, preferring `@State`, `@Environment`, and lightweight orchestration via `.task` or `onChange` before introducing a view model.

How do I split a complex SwiftUI screen into focused subviews?▼

To split a complex SwiftUI screen, reorder `Environment`, stored properties, `init`, and `body` to read top-to-bottom as data flow plus UI, then extract meaningful subviews while standardizing dependency injection via `@Environment`.

When should I avoid top-level conditional root swapping in SwiftUI?▼

You should avoid top-level conditional root swapping in SwiftUI to ensure a stable view tree. Reordering code to match view ordering rules and preventing root swapping reduces brittle views and maintains runtime stability.