swiftui-view-refactor

Refactor large SwiftUI view files into small, stable, testable view types.

Updated Jul 31, 2026
One-click install
npx skills add https://github.com/AarnavBaddam/skills --skill swiftui-view-refactor-aarnavbaddam
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-view-refactor
Source: https://github.com/AarnavBaddam/skills/tree/main/swiftui-view-refactor
Command: npx skills add https://github.com/AarnavBaddam/skills --skill swiftui-view-refactor-aarnavbaddam

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? SwiftUI view files often grow into long, tangled bodies mixing layout, business logic, and conditional branching, making them hard to read, test, and maintain. This Skill restructures those views into small, explicit, stable view types without changing behavior. ## Core Features & Use Cases - View Structure Enforcement: Reorders view members (environment, state, init, body, helpers) and extracts dedicated subview types instead of computed some View fragments. - MV-First Data Flow: Keeps logic in services and models using @State, @Environment, @Query, and lifecycle modifiers, avoiding unnecessary view models. - Stable View Trees: Eliminates top-level conditional branch swapping and moves business logic out of body, .task, and .onAppear. - Use Case: Given a 400-line SwiftUI screen with inline actions and nested conditionals, split it into dedicated subview types with explicit inputs while preserving layout and behavior. ## Quick Start Use the swiftui-view-refactor skill to clean up and split this SwiftUI view file without changing its behavior.

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 large SwiftUI view file?

Split the body into dedicated subview types with small explicit inputs like data, bindings, and callbacks. Move business logic into services or models, keep only thin orchestration in the view, and reorder members so environment, state, init, body, and helpers follow a consistent top-to-bottom order.

Should I use MVVM or MV in SwiftUI?

Default to MV: views act as lightweight state expressions using @State, @Environment, @Query, and lifecycle modifiers, with business logic in services and models. Introduce a view model only when explicitly requested, required by existing code, or when shared presentation state genuinely needs a long-lived reference object.

How do I use @Observable with @State in SwiftUI on iOS 17?

Store @Observable reference types as @State in the owning view on iOS 17 and later, and pass them down explicitly to child views. For deployment targets including iOS 16 or earlier, use @StateObject at the owner and @ObservedObject for injected legacy observable models.

Why should I avoid computed some View properties in SwiftUI?

Computed some View helpers hide structure and make large screens harder to reason about when overused. Dedicated subview types get their own identity, state, previews, and explicit inputs, which improves stability and testability; keep computed helpers rare and small.

When should I not add a view model in SwiftUI?

Avoid a view model when it would only mirror local view state, wrap environment dependencies, duplicate @Query or Binding data flow, or exist just because the body is too long. Split the view into smaller types and move logic into services instead of adding indirection.