swiftui-view-refactor

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

3|1|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/heyAyushh/stacc --skill swiftui-view-refactor-heyayushh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/heyAyushh/stacc/tree/main/configs/stacks/ios/swiftui-view-refactor
Command: npx skills add https://github.com/heyAyushh/stacc --skill swiftui-view-refactor-heyayushh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill guides developers in refactoring and reviewing SwiftUI view files to enforce a consistent structure, safe dependency injection, and careful observation usage. It helps teams standardize layout/ordering, handle view-models safely (prefer non-optional when possible), and ensure dependencies and @Observable state are initialized and passed correctly.

Core Features & Use Cases

  • Consistent structure: Enforces a top-to-bottom ordering of SwiftUI view components and stored properties.
  • MV-first guidance: Encourages lightweight views and proper separation of business logic into services/models, using @Environment, @State, @Query, and task/onChange for orchestration.
  • Safety & maintainability: Promotes non-optional view models when present, clear dependency injection, and readable, composable subviews.
  • Use Case: When refactoring large SwiftUI views, apply these guidelines to reduce boilerplate and improve testability.

Quick Start

Open your SwiftUI view file and apply the ordering and patterns described to reorganize the view, inject dependencies via Environment, and extract complex sections into subviews as needed. Then run the app to 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 refactor a SwiftUI view to enforce consistent structure and safe dependency injection?

Refactor SwiftUI views by applying a top-to-bottom ordering for components and stored properties, injecting dependencies explicitly via @Environment, and initializing non-optional view models to ensure safe structure and readability.

What is the best way to handle @Observable state and view models in SwiftUI MV patterns?

Handle @Observable state in SwiftUI MV patterns by separating business logic into lightweight services and models, prefering non-optional view models, and using @State, @Query, and task or onChange modifiers for orchestration.

How do you organize SwiftUI view files to promote lightweight views and testability?

Organize SwiftUI view files by extracting complex sections into composable subviews, applying consistent layout ordering, and moving business logic out of views into models or services to improve testability and reduce boilerplate.

Can I use environment injection for complex SwiftUI screens with multiple dependencies?

Yes, you can use explicit @Environment injection to pass dependencies across complex SwiftUI screens, ensuring that state and view models are initialized correctly and passed safely without optionals when possible.

When should I not use optional view models in SwiftUI architecture?

Avoid optional view models in SwiftUI architecture when dependencies can be initialized safely at creation, prefering non-optional instances to reduce unwrapping boilerplate and ensure dependencies and @Observable state are passed correctly.

Does refactoring SwiftUI views with MV patterns require removing all business logic from the view body?

Refactoring SwiftUI views with MV patterns encourages removing business logic from the view body by leveraging @Environment, @State, and task or onChange for orchestration, while keeping the views lightweight and focused on layout.