swiftui-mvvm-architecture

Migrate SwiftUI apps to MVVM with @Observable, typed routing, and constructor injection.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/rusel95/WhiteNoise --skill swiftui-mvvm-architecture
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-mvvm-architecture
Source: https://github.com/rusel95/WhiteNoise/tree/main/.claude/skills/swiftui-mvvm-architecture
Command: npx skills add https://github.com/rusel95/WhiteNoise --skill swiftui-mvvm-architecture

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Modern SwiftUI apps often suffer from maintenance challenges when evolving legacy patterns. This skill provides a production-first path to migrate codebases to an MVVM architecture using @Observable, a typed Router, and dependency injection, enabling safer, incremental refactors.

Core Features & Use Cases

  • Phased refactoring workflow using a refactoring/ directory to ship small, reviewable PRs
  • Adoption of @Observable @MainActor ViewModels to improve testability and reduce redraws
  • Typed navigation with a Router and Route enum to replace fragile string-based paths
  • Protocol-based DI via constructor injection to enable mocking and easier testing
  • Guidance for creating new screens and migrating from ObservableObject with measurable boundaries

Quick Start

Provide a legacy SwiftUI screen and instruct the AI to migrate it to an @Observable ViewModel, router-based navigation, and constructor DI in small, reviewable PRs.

Frequently Asked Questions about swiftui-mvvm-architecture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate SwiftUI apps from ObservableObject to @Observable for MVVM?

Migrating SwiftUI apps from ObservableObject to @Observable involves adopting @MainActor ViewModels, constructor injection, and typed routing. This skill provides a phased refactoring workflow to ship small, reviewable PRs for safer incremental transitions.

What's the best way to implement typed navigation in SwiftUI instead of string-based paths?

Typed navigation in SwiftUI replaces fragile string-based paths with a typed Router and Route enum. This architecture ensures compile-time safety for navigation destinations and integrates directly with @Observable ViewModels.

How does dependency injection work with SwiftUI ViewModels for testability?

Dependency injection with SwiftUI ViewModels uses protocol-based constructor injection to enable mocking and easier testing. By injecting dependencies through the initializer, you isolate ViewModels for unit tests without relying on global state or singletons.

Can I refactor legacy SwiftUI code into MVVM incrementally without breaking existing features?

You can refactor legacy SwiftUI code incrementally using a refactoring/ directory to track phased changes. This workflow enforces measurable boundaries, allowing you to migrate screens individually and ship small, reviewable PRs.

Why does my SwiftUI ViewModel cause excessive view redraws and how can @Observable fix it?

SwiftUI ViewModels cause excessive redraws when using ObservableObject due to broad state observation. Adopting @Observable fixes this by enabling granular observation, ensuring views only redraw when the specific properties they read actually change.

Do I need a dedicated state object for async data loading in SwiftUI MVVM?

You need a dedicated ViewState for async data loading in SwiftUI MVVM to track loading, loaded, and error states. This pattern pairs with @Observable @MainActor ViewModels to safely manage asynchronous data fetching and UI updates.