swiftui-mvvm-pattern

Create SwiftUI views with ObservableObject ViewModels and @Published data binding.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/co-labs-co/context-harness-skills --skill swiftui-mvvm-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-mvvm-pattern
Source: https://github.com/co-labs-co/context-harness-skills/tree/main/skill/swiftui-mvvm-pattern
Command: npx skills add https://github.com/co-labs-co/context-harness-skills --skill swiftui-mvvm-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

MVVM in SwiftUI often leads to scattered logic and hard-to-test UI code. This guide provides a structured approach to separate concerns, wire up ObservableObject view models, and promote testable, reusable components.

Core Features & Use Cases

  • Structured ViewModel creation with ObservableObject and @Published properties
  • View composition using @StateObject and data binding for responsive UI
  • Clear data flow across common screen scenarios (list/detail, search, form input)

Quick Start

Create a ViewModel class conforming to ObservableObject with @Published properties, instantiate it in a SwiftUI view using @StateObject, and bind UI controls to the published properties to enable real-time updates.

Frequently Asked Questions about swiftui-mvvm-pattern

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

FAQPage Schema
How do I set up MVVM data binding in SwiftUI with ObservableObject?

SwiftUI MVVM data binding uses an ObservableObject ViewModel with @Published properties, instantiated in a view via @StateObject, enabling real-time UI updates when state changes.

What is the best way to separate UI logic from views in a SwiftUI app?

Separating UI logic in SwiftUI uses an MVVM blueprint where ViewModels conform to ObservableObject, keeping views clean and promoting testable, reusable components.

Why does my SwiftUI view model state not update the UI?

SwiftUI view model state fails to update the UI if properties lack the @Published wrapper or the view uses @StateObject incorrectly, breaking the ObservableObject data binding cycle.

Do I need to use @StateObject or @ObservedObject for SwiftUI ViewModel instantiation?

Use @StateObject for SwiftUI ViewModel instantiation when the view creates the ObservableObject, ensuring the instance persists across view updates and maintains stable state.