viewmodel

Architect stateful SwiftUI ViewModels with ViewState and protocol-based UseCase injection.

Updated Jan 15, 2026
One-click install
npx skills add https://github.com/vjr2005/Challenge --skill viewmodel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: viewmodel
Source: https://github.com/vjr2005/Challenge/tree/main/.claude/skills/viewmodel
Command: npx skills add https://github.com/vjr2005/Challenge --skill viewmodel

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building and maintaining stateful ViewModels for SwiftUI apps can be verbose and error-prone. This skill provides a ready-to-use pattern to encapsulate view state, coordinate between views and use cases, and enforce testable, predictable behavior with minimal boilerplate.

Core Features & Use Cases

  • ViewState pattern for local state management with an internal, non-public state that supports idle, loading, loaded, and error states.
  • Structured ViewModel patterns for detail views (with navigation) and list views (with optional navigation and tracking), including conventions for public lifecycle methods like didAppear() and didTapOnRetryButton().
  • Protocol-based dependency injection for UseCases, NavigatorContract, and TrackerContract to promote testability and modularity, while keeping navigation and tracking concerns encapsulated within dedicated components.
  • Testing guidance and example Integrations for ensuring state transitions, navigation, and tracking behaviors are verifiable.

Quick Start

Create a new ViewModel by applying the ViewState pattern and the recommended file structure for a feature.

Frequently Asked Questions about viewmodel

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

FAQPage Schema
How do I manage SwiftUI view state across loading and error scenarios?

Manage SwiftUI view state using the ViewState pattern to encapsulate idle, loading, loaded, and error states. This approach coordinates views and use cases while keeping state transitions predictable and testable with minimal boilerplate.

How do I structure a SwiftUI ViewModel for unit testing?

Structure SwiftUI ViewModels for unit testing by applying protocol-based dependency injection for UseCases, NavigatorContract, and TrackerContract. This design promotes modularity and ensures state transitions, navigation, and tracking behaviors remain fully verifiable.

What is the best way to handle navigation logic in SwiftUI without cluttering the ViewModel?

Handle navigation logic by encapsulating it within a dedicated NavigatorContract component rather than the ViewModel. The ViewModel coordinates with this protocol-based contract, keeping navigation concerns modular and separate from local state management.

Can I use protocol-based dependency injection for SwiftUI feature development?

Yes, you can use protocol-based dependency injection for SwiftUI feature development. Injecting UseCases, NavigatorContract, and TrackerContract protocols promotes testability and modularity while coordinating view state and business logic.

How do I implement lifecycle methods in SwiftUI ViewModels?

Implement lifecycle methods in SwiftUI ViewModels by exposing public methods like didAppear() and didTapOnRetryButton() while keeping the actual load logic private. This structure ensures consistent naming conventions for navigation and tests.

Does this ViewModel pattern support both list views and detail views in SwiftUI?

Yes, this ViewModel pattern supports both list views and detail views in SwiftUI. It provides structured patterns for detail views with navigation and list views with optional navigation and tracking integration.