generate screen
Create a screen (View + ViewModel) and auto-wire its route + navigation.
Creates a paired SwiftUI View and @MainActor @Observable ViewModel, registers a route for it, and wires the navigation switch.
Synopsis
Section titled “Synopsis”swiftspawn generate screen <Name> [--on <feature>] [--uses <services>] [--with-tests] [--no-route] [--dry-run] [--force] [--quiet] [--verbose]Description
Section titled “Description”A screen is a destination users navigate to. It always comes as a pair: a SwiftUI view and a ViewModel. The ViewModel holds the screen’s state (idle / loading / loaded(value) / failed(error) is a common shape) and calls services.
The View suffix is appended automatically: generate screen MovieList produces MovieListView.swift.
--uses <services> tells the generator which services the ViewModel depends on. They become @Injected properties on the ViewModel and are registered in DIContainer.swift between the auto-managed markers.
--no-route skips the route entry, useful for screens that need parameters in the route case (you’ll add the case manually).
--on <feature> (or the bare on Movies form) places the screen under Features/<Feature>/. Without it, the screen lives directly under Features/.
Examples
Section titled “Examples”swiftspawn generate screen Homeswiftspawn generate screen MovieList on Movies --uses MovieServiceswiftspawn generate screen Profile --uses UserService,SettingsService --with-testsGenerated files
Section titled “Generated files”Features/<Feature>/<Name>/<Name>View.swiftFeatures/<Feature>/<Name>/<Name>ViewModel.swiftWith --with-tests:
Tests/<App>Tests/Features/<Feature>/<Name>/<Name>ViewModelTests.swiftSide effects
Section titled “Side effects”- Adds
case <name>toRoute.swiftbetween// MARK: - Cases (auto-generated)markers (unless--no-route). - Adds
case .<name>: <Name>View()toRootView.swift’sswitch routebetween its markers. - Registers each service in
--usesinDIContainer.swiftbetween its markers.
If those marker comments don’t exist (legacy projects), the generator prints the snippet to paste in instead of editing.
Options
Section titled “Options”| Flag | Description |
|---|---|
--on <feature> | Feature folder to nest the screen under. Bare on <feature> also works. |
--uses <services> | Comma-separated services the ViewModel depends on. |
--with-tests | Also emit a ViewModel test file. |
--no-route | Skip the Route.swift case (write screen files only). |
--dry-run | Preview without writing. |
--force | Overwrite existing files. |
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 2 | Invalid name. |
| 5 | Not in a swiftspawn project. |
| 7 | Route.swift is missing the markers. |
| 12 | Route case already exists. |
See also
Section titled “See also”generate viewfor a view without a ViewModel.generate service- Markers