A toolkit for building and capturing SwiftUI previews for visual analysis.
# Standalone Swift file (no external dependencies)
./scripts/preview MyView.swift
# File in an Xcode project (auto-injects PreviewHost target)
./scripts/preview ContentView.swift --project MyApp.xcodeproj
# File in an SPM package
./scripts/preview Sources/Module/MyView.swift
# Just capture current simulator
./scripts/preview --capture-only| Project Type | Approach | Build Time | Script |
|---|---|---|---|
| Standalone Swift | Minimal host app | ~5 seconds | preview-minimal.sh |
| Xcode project | Dynamic target injection | ~3-4 seconds | preview-tool |
| SPM package | Temporary project creation | ~20 seconds | preview-tool |
For Xcode projects, the toolkit:
- Parses the Swift file to extract
#Preview { }content - Injects a temporary
PreviewHosttarget into the project - Configures dependencies based on imports
- Detects and includes resource bundles (Tuist, standard naming)
- Builds only the required modules
- Captures screenshot
- Cleans up the injected target
This is much faster than building a full app scheme.
| Path | Purpose |
|---|---|
scripts/preview |
Unified entry point - auto-detects best approach |
scripts/preview-minimal.sh |
Build standalone Swift files |
scripts/xcode-preview.sh |
Build full Xcode project schemes |
scripts/capture-simulator.sh |
Screenshot current simulator |
scripts/sim-manager.sh |
Simulator management |
tools/preview-tool |
Swift CLI for dynamic preview injection, SPM preview, dependency resolution |
./scripts/preview templates/StandalonePreview.swift./scripts/preview Modules/Components/Chip/Chip.swift \
--project MyApp.xcodeproj./scripts/preview Sources/IronPrimitives/Button/IronButton.swift./scripts/preview MyView.swift \
--output ~/Desktop/preview.png \
--simulator "iPhone 16 Pro" \
--verbose- macOS with Xcode installed
- iOS Simulator
- Swift toolchain (preview-tool auto-builds on first run)
When asked to preview a SwiftUI view:
-
Run the preview script:
./scripts/preview path/to/MyView.swift --output /tmp/preview.png
-
View the screenshot:
Read /tmp/preview.png -
Analyze and report: Describe layout, styling, colors, and any issues
The /preview skill is defined in .claude/commands/preview.md for use with Claude Code.