scaffold_viewmodel
Generate a new Swift file containing an @Observable class (or ObservableObject for older deployment targets) that serves as a view model in the MVVM pattern. The generated file includes the proper imports and a clean starting structure ready for you to add properties and methods.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | — | The name of the view model (e.g., "ProfileHeader" generates ProfileHeaderViewModel.swift) |
outputPath | string | Yes | — | Absolute path to the directory where the file will be created |
Usage Examples
Section titled “Usage Examples”Create a view model for a profile screen
Section titled “Create a view model for a profile screen”“Create a view model for the ProfileHeader view”
{ "name": "ProfileHeader", "outputPath": "/Users/dev/Projects/FitnessTracker/FitnessTracker/ViewModels"}Create a view model for a data-heavy screen
Section titled “Create a view model for a data-heavy screen”“Scaffold a WorkoutHistory view model in the ViewModels directory”
{ "name": "WorkoutHistory", "outputPath": "/Users/dev/Projects/FitnessTracker/FitnessTracker/ViewModels"}Create a view model in a feature-based folder structure
Section titled “Create a view model in a feature-based folder structure”“Generate a view model called MealPlanner inside the Nutrition feature folder”
{ "name": "MealPlanner", "outputPath": "/Users/dev/Projects/FitnessTracker/FitnessTracker/Features/Nutrition"}Example Output
Section titled “Example Output”Created view model file: /Users/dev/Projects/FitnessTracker/FitnessTracker/ViewModels/ProfileHeaderViewModel.swift
File contents: import Foundation import Observation
@Observable final class ProfileHeaderViewModel {
}Related Tools
Section titled “Related Tools”scaffold_view— Create a matching SwiftUI view for this view modelscaffold_coredata_model— Generate a Core Data model if the view model needs persistent storageproject_create— Create a new project with the full directory structure