swiftui-view-refactor

Refactor SwiftUI view files into small subviews with MV-first data flow.

Updated Apr 6, 2026
One-click install
npx skills add https://github.com/jperezdelreal/GymBro --skill swiftui-view-refactor-jperezdelreal
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/jperezdelreal/GymBro/tree/main/.squad/skills/ios/swiftui-view-refactor
Command: npx skills add https://github.com/jperezdelreal/GymBro --skill swiftui-view-refactor-jperezdelreal

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactor and review SwiftUI view files with strong defaults for small dedicated subviews, MV-over-MVVM data flow, stable view trees, explicit dependency injection, and correct Observation usage. Use when cleaning up a SwiftUI view, splitting long bodies, removing inline actions or side effects, reducing computed some View helpers, or standardizing @Observable and view model initialization patterns.

Core Features & Use Cases

  • Subview extraction and modularization to simplify complex screens
  • MV-first data flow over MVVM to reduce coupling and improve testability
  • Explicit dependency injection via environment or initializer to improve testability
  • Stable view trees by avoiding large, top-level conditional root views
  • Guidance on avoiding side effects in view bodies and moving logic into services/models
  • Standardization of observation usage and view model initialization patterns

Quick Start

Begin by identifying a large SwiftUI view, break it into smaller subviews, and apply explicit dependency injection and MV-first patterns.

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 to follow MVVM patterns?

Refactoring a SwiftUI view for MVVM involves splitting long view bodies into small dedicated subviews, removing inline side effects, and standardizing view model initialization. This approach keeps view bodies thin and aligns data flow with MV-first patterns.

What is the best way to split a complex SwiftUI view body into smaller subviews?

The best way to split complex SwiftUI views is extracting subviews to modularize screens and simplify view trees. Avoid large top-level conditional root views and prefer environment dependencies to maintain a stable, readable view hierarchy.

Why should I remove inline actions and side effects from SwiftUI view bodies?

Removing inline actions and side effects from SwiftUI view bodies ensures a stable view tree and improves testability. Moving non-trivial logic into services or models aligns with MV-first data flow and keeps view bodies strictly declarative.

How do I standardize @Observable usage when cleaning up SwiftUI views?

Standardizing @Observable usage requires applying correct observation patterns and explicit dependency injection during SwiftUI view cleanup. This ensures view models are initialized correctly and reduces coupling within the view hierarchy.

Does this SwiftUI refactoring approach use explicit dependency injection over environment objects?

This refactoring approach prefers explicit dependency injection via environment or initializer to improve testability. It applies MV-first data flow over traditional MVVM to reduce coupling while maintaining a stable view tree.

When should I avoid using computed some View properties in SwiftUI?

You should avoid non-trivial computed some View helpers when they contain complex logic or side effects. Refactoring these into extracted subviews and moving logic into models or services keeps SwiftUI view bodies thin and maintainable.