swiftui-view-refactor

Refactor SwiftUI view files to enforce consistent structure and Observation handling.

1|1|Updated Jun 2, 2025
One-click install
npx skills add https://github.com/BumpyClock/dotfiles --skill swiftui-view-refactor-bumpyclock
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/BumpyClock/dotfiles/tree/main/.ai_agents/skills/swiftui-view-refactor
Command: npx skills add https://github.com/BumpyClock/dotfiles --skill swiftui-view-refactor-bumpyclock

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Refactor SwiftUI view files to enforce consistent structure, proper dependency injection, and correct Observation usage across projects.

Core Features & Use Cases

  • Enforces a top-to-bottom view ordering: Environment, private/public lets, @State, computed properties, init, body, then helpers.
  • Encourages MV patterns by keeping views lightweight and pushing business logic to services/models via @Environment and orchestration with @State/@Query.
  • Suggests splitting large bodies into subviews and extracting complex sections into dedicated Views to improve readability and reuse.
  • Ensures proper Observation usage and non-optional view state where appropriate, reducing boilerplate and crash risk.
  • Use Case: refactor a large SwiftUI view with nested components into smaller pieces without affecting layout.

Quick Start

Provide the SwiftUI view file to refactor, and I will reorder the view, extract subviews, and adjust dependency and observation usage according to the guidelines.

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 enforce consistent structure and safe dependency management?

To refactor SwiftUI views, you enforce a top-to-bottom ordering: Environment, properties, @State, computed properties, init, body, then helpers. This standardizes environment usage and ensures proper Observation handling to improve maintainability and readability.

What is the best way to split large SwiftUI view bodies into smaller subviews?

Splitting large SwiftUI view bodies involves extracting complex sections into dedicated subviews. This improves readability and reuse while keeping views lightweight and pushing business logic to services and models via MV patterns.

How does Observation usage work when cleaning up complex SwiftUI views?

Observation usage in SwiftUI refactoring ensures proper state handling and non-optional root state where appropriate. This reduces boilerplate and crash risk while orchestrating state correctly with @State and @Environment.

Can I use MV patterns to push business logic out of my SwiftUI views?

Yes, you can use MV patterns to push business logic to services and models. This keeps views lightweight by orchestrating state with @State and managing dependencies through @Environment.

Why does my SwiftUI view crash when state is optional during refactoring?

SwiftUI views may crash with optional state due to unsafe dependency management. Enforcing non-optional root state where appropriate during refactoring reduces crash risk and eliminates related boilerplate.