swiftui-view-refactor

Refactor SwiftUI views into MV-structured components with consistent ordering.

3.9k|203|Updated Dec 30, 2025
One-click install
npx skills add https://github.com/Dimillian/Skills --skill swiftui-view-refactor-dimillian
Or copy as Structured Prompt for Agentβ–Ό
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/Dimillian/Skills/tree/main/swiftui-view-refactor
Command: npx skills add https://github.com/Dimillian/Skills --skill swiftui-view-refactor-dimillian

SYSTEM DOCUMENTATION & REQUIREMENTS

πŸ’‘ This Skill includes references (resource) components.

What problem does it solve?

Refactors and reviews SwiftUI view files to enforce a consistent structure, safe dependency injection, and proper Observation usage, reducing layout drift and improving maintainability.

Core Features & Use Cases

  • Enforces a stable view ordering: Environment β†’ private/public lets β†’ @State and other stored properties β†’ computed vars β†’ init β†’ body β†’ helpers
  • Promotes MV patterns and explicit dependencies via Environment and Observation for small, composable views
  • Encourages splitting large bodies into subviews and extracting complex pieces into dedicated view builders
  • Maintains a stable view tree and avoids top-level conditional swapping

Quick Start

  • Review a target SwiftUI view file and identify sections to reorganize
  • Apply the prescribed ordering, MV patterns, and explicit dependency injection
  • Split large bodies into subviews and verify behavior remains unchanged

Frequently Asked Questions about swiftui-view-refactor

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

FAQPage Schema
How do I enforce a consistent property ordering structure in SwiftUI views?β–Ό

To enforce consistent property ordering in SwiftUI views, organize properties sequentially: Environment, private and public lets, @State stored properties, computed vars, init, body, and helper functions. This structure reduces layout drift and improves maintainability.

What is the best way to handle dependency injection in SwiftUI using the MV pattern?β–Ό

The best way to handle dependency injection in SwiftUI using the MV pattern is through explicit dependencies via Environment and Observation, using non-optional view models when needed to ensure safe, testable state flow across small, composable views.

When should I split large SwiftUI body properties into subviews?β–Ό

You should split large SwiftUI body properties into subviews when refactoring to maintain a stable view tree, extract complex pieces into dedicated view builders, and avoid top-level conditional swapping that causes layout drift.

Why does my SwiftUI view tree become unstable during state changes?β–Ό

Your SwiftUI view tree becomes unstable during state changes when top-level conditional swapping occurs. Refactoring to maintain a stable view tree and using explicit Observation prevents this layout drift.

Can I use the MV pattern without optional view models in SwiftUI?β–Ό

Yes, you can use the MV pattern with non-optional view models in SwiftUI. Enforcing non-optional view models when needed ensures safe dependency handling and controlled state flow across your refactored views.

How do I refactor an existing SwiftUI view for testability?β–Ό

To refactor an existing SwiftUI view for testability, apply consistent property ordering, adopt the MV pattern with explicit Observation, and split large bodies into subviews to transform it into a clean, testable component.