swiftui-view-refactor

Refactor SwiftUI view files for layout ordering and @Observable usage.

1|Updated Feb 24, 2026
One-click install
npx skills add https://github.com/kmshdev/claude-swift-toolkit --skill swiftui-view-refactor-kmshdev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/kmshdev/claude-swift-toolkit/tree/main/skills/swiftui-view-refactor
Command: npx skills add https://github.com/kmshdev/claude-swift-toolkit --skill swiftui-view-refactor-kmshdev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Refactoring and standardizing SwiftUI view structures to improve readability, maintainability, and predictable state management across large view hierarchies.

Core Features & Use Cases

  • Establish consistent view ordering from top to bottom (Environment, stored properties, state, init, body, helpers).
  • Enforce MV patterns by keeping business logic in services and using lightweight views with explicit state management via @State/@Environment/@Query, minimizing or eliminating ViewModel usage where possible.
  • Split large views into smaller subviews to improve readability and reusability; provide guidelines for extracting header, detail, and action sections as separate views.

Quick Start

Open a SwiftUI view file and apply the refactor guidelines to improve layout order, dependency injection, and observable state handling.

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 SwiftUI views for clean layout ordering and state management?

Refactoring SwiftUI views involves reordering components top to bottom—Environment, stored properties, state, init, body, and helpers—to ensure predictable state management and consistent view composition across large hierarchies.

What is the best way to apply MV patterns in SwiftUI without heavy ViewModels?

Applying MV patterns in SwiftUI involves keeping business logic in services while using lightweight views with explicit state management via @State, @Environment, and @Query, minimizing or eliminating ViewModel usage where possible.

How do I split large SwiftUI views into smaller subviews?

Splitting large SwiftUI views requires extracting header, detail, and action sections as separate subviews. This improves readability and reusability while preserving the original behavior and consistent view composition.

Does this SwiftUI refactoring approach support dependency injection and @Observable usage?

Yes, this refactoring approach explicitly supports dependency injection and @Observable usage. It applies safe non-optional view models when needed and satisfies requirements for environment injection and observable state handling.

Can I use this refactoring method for SwiftUI projects with complex view hierarchies?

Yes, this refactoring method is designed for SwiftUI projects with complex hierarchies requiring consistent view composition, explicit state orchestration, and safe non-optional view models to maintain predictable state management.