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.