swiftui-view-refactor

Refactor SwiftUI view files to enforce consistent structure and dependency injection.

42|11|Updated Dec 26, 2025
One-click install
npx skills add https://github.com/petekp/claude-code-setup --skill swiftui-view-refactor-petekp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/petekp/claude-code-setup/tree/main/skills/swiftui-view-refactor
Command: npx skills add https://github.com/petekp/claude-code-setup --skill swiftui-view-refactor-petekp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the complexity and potential disorganization in SwiftUI views by enforcing consistent structure, safe dependency handling, and optimal usage of modern SwiftUI features like Observation.

Core Features & Use Cases

  • Code Organization: Reorders view elements according to established best practices (Environment, State, Body, Helpers).
  • Dependency Management: Guides safe initialization and injection of view models and services, favoring @Environment and @State.
  • Modern SwiftUI Adoption: Ensures correct usage of @Observable and other state management tools.
  • Use Case: When a SwiftUI view becomes long and difficult to navigate, use this Skill to automatically reformat it, split large computed properties into subviews, and ensure view models are handled correctly.

Quick Start

Refactor the attached SwiftUI view file to adhere to the MV pattern and improve its structure.

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 to enforce a consistent structure?

To refactor SwiftUI views, you reorganize view elements into a standard order: Environment, State, Body, and Helpers. This process splits large computed properties into subviews and standardizes initialization to enforce consistent MV pattern structure and improve code clarity.

What is the best way to handle view models and dependencies in SwiftUI?

Handling view models safely requires favoring `@Environment` and `@State` for dependency injection. This approach guides safe initialization and passing of services, ensuring proper usage of the Observation framework and standardizing how dependencies are managed within your views.

How does the Observation framework work with @Observable state in SwiftUI?

The Observation framework works by using `@Observable` to track state changes and drive view updates. Proper adoption ensures correct usage of modern state management tools, replacing older patterns to safely handle view models and standardize state initialization within SwiftUI views.

Can I use this refactoring approach for SwiftUI views that are long and difficult to navigate?

Yes, this refactoring approach is designed for long and difficult-to-navigate SwiftUI views. It automatically reformats the view file, splits large computed properties into smaller subviews, and enforces consistent structure to improve readability and maintainability.

When do I need to standardize dependency injection in SwiftUI views?

You need to standardize dependency injection when view models and services are handled incorrectly or inconsistently. Applying safe initialization practices using `@Environment` and `@State` ensures proper dependency passing and enforces the MV pattern within your SwiftUI views.