swiftui-view-generator
Generate SwiftUI views with proper state management (@State, @Binding, @ObservedObject, @StateObject) and macOS-specific patterns
Best use case
swiftui-view-generator is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Generate SwiftUI views with proper state management (@State, @Binding, @ObservedObject, @StateObject) and macOS-specific patterns
Teams using swiftui-view-generator should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/swiftui-view-generator/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How swiftui-view-generator Compares
| Feature / Agent | swiftui-view-generator | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Generate SwiftUI views with proper state management (@State, @Binding, @ObservedObject, @StateObject) and macOS-specific patterns
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# swiftui-view-generator
Generate SwiftUI views with proper state management for macOS applications. This skill creates well-structured SwiftUI components using @State, @Binding, @ObservedObject, @StateObject, and @EnvironmentObject property wrappers.
## Capabilities
- Generate SwiftUI views with proper state management
- Create reusable view components
- Set up data flow with Combine
- Implement navigation patterns
- Generate macOS-specific UI elements
- Create preference-based layouts
- Set up environment values
- Generate preview providers
## Input Schema
```json
{
"type": "object",
"properties": {
"projectPath": {
"type": "string",
"description": "Path to the Swift project"
},
"viewName": {
"type": "string",
"description": "Name of the view to generate"
},
"viewType": {
"enum": ["screen", "component", "list", "form", "settings", "sheet"],
"default": "screen"
},
"stateProperties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"type": { "type": "string" },
"wrapper": { "enum": ["State", "Binding", "ObservedObject", "StateObject", "EnvironmentObject"] }
}
}
},
"includeViewModel": {
"type": "boolean",
"default": true
},
"macOSSpecific": {
"type": "boolean",
"default": true
}
},
"required": ["projectPath", "viewName"]
}
```
## Output Schema
```json
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"files": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"type": { "enum": ["view", "viewmodel", "model"] }
}
}
}
},
"required": ["success"]
}
```
## Generated SwiftUI View Example
```swift
// ContentView.swift
import SwiftUI
struct ContentView: View {
@StateObject private var viewModel = ContentViewModel()
@State private var searchText = ""
@State private var isShowingSettings = false
var body: some View {
NavigationSplitView {
// Sidebar
SidebarView(selection: $viewModel.selectedCategory)
} detail: {
// Detail view
if let category = viewModel.selectedCategory {
CategoryDetailView(category: category)
} else {
Text("Select a category")
.foregroundStyle(.secondary)
}
}
.searchable(text: $searchText, prompt: "Search items...")
.onChange(of: searchText) { _, newValue in
viewModel.search(query: newValue)
}
.toolbar {
ToolbarItemGroup {
Button(action: viewModel.refresh) {
Label("Refresh", systemImage: "arrow.clockwise")
}
Button(action: { isShowingSettings = true }) {
Label("Settings", systemImage: "gear")
}
}
}
.sheet(isPresented: $isShowingSettings) {
SettingsView()
}
.task {
await viewModel.loadData()
}
}
}
// MARK: - Preview
#Preview {
ContentView()
}
#Preview("With Data") {
ContentView()
.environmentObject(PreviewData.sampleViewModel)
}
```
### ViewModel
```swift
// ContentViewModel.swift
import SwiftUI
import Combine
@MainActor
class ContentViewModel: ObservableObject {
@Published var items: [Item] = []
@Published var selectedCategory: Category?
@Published var isLoading = false
@Published var errorMessage: String?
private let dataService: DataService
private var cancellables = Set<AnyCancellable>()
init(dataService: DataService = .shared) {
self.dataService = dataService
}
func loadData() async {
isLoading = true
errorMessage = nil
do {
items = try await dataService.fetchItems()
} catch {
errorMessage = error.localizedDescription
}
isLoading = false
}
func search(query: String) {
// Debounced search implementation
Task {
try? await Task.sleep(nanoseconds: 300_000_000)
// Perform search
}
}
func refresh() {
Task {
await loadData()
}
}
}
```
### Reusable Component
```swift
// ItemRowView.swift
import SwiftUI
struct ItemRowView: View {
let item: Item
@Binding var isSelected: Bool
var onDelete: (() -> Void)?
var body: some View {
HStack {
Image(systemName: item.icon)
.foregroundStyle(item.color)
.frame(width: 24, height: 24)
VStack(alignment: .leading, spacing: 4) {
Text(item.title)
.font(.headline)
Text(item.subtitle)
.font(.subheadline)
.foregroundStyle(.secondary)
}
Spacer()
if isSelected {
Image(systemName: "checkmark")
.foregroundStyle(.blue)
}
}
.padding(.vertical, 4)
.contentShape(Rectangle())
.onTapGesture {
isSelected.toggle()
}
.contextMenu {
Button("Edit") { }
Button("Duplicate") { }
Divider()
Button("Delete", role: .destructive) {
onDelete?()
}
}
}
}
```
### Settings View (macOS)
```swift
// SettingsView.swift
import SwiftUI
struct SettingsView: View {
var body: some View {
TabView {
GeneralSettingsView()
.tabItem {
Label("General", systemImage: "gear")
}
AppearanceSettingsView()
.tabItem {
Label("Appearance", systemImage: "paintpalette")
}
AdvancedSettingsView()
.tabItem {
Label("Advanced", systemImage: "slider.horizontal.3")
}
}
.frame(width: 500, height: 400)
}
}
struct GeneralSettingsView: View {
@AppStorage("launchAtLogin") private var launchAtLogin = false
@AppStorage("checkForUpdates") private var checkForUpdates = true
var body: some View {
Form {
Toggle("Launch at Login", isOn: $launchAtLogin)
Toggle("Check for Updates Automatically", isOn: $checkForUpdates)
}
.formStyle(.grouped)
.padding()
}
}
```
### List View with Selection
```swift
// ItemListView.swift
import SwiftUI
struct ItemListView: View {
@ObservedObject var viewModel: ItemListViewModel
@State private var selection: Set<Item.ID> = []
@State private var sortOrder = [KeyPathComparator(\Item.name)]
var body: some View {
Table(viewModel.items, selection: $selection, sortOrder: $sortOrder) {
TableColumn("Name", value: \.name)
TableColumn("Type", value: \.type)
TableColumn("Modified", value: \.modifiedDate) { item in
Text(item.modifiedDate, style: .date)
}
TableColumn("Size") { item in
Text(ByteCountFormatter.string(fromByteCount: item.size, countStyle: .file))
}
.width(80)
}
.onChange(of: sortOrder) { _, newOrder in
viewModel.sort(by: newOrder)
}
.contextMenu(forSelectionType: Item.ID.self) { items in
Button("Open") { viewModel.open(items) }
Button("Delete", role: .destructive) { viewModel.delete(items) }
} primaryAction: { items in
viewModel.open(items)
}
}
}
```
## State Management Patterns
### @State - Local state
```swift
@State private var isExpanded = false
@State private var selectedTab = 0
```
### @Binding - Two-way binding from parent
```swift
@Binding var isPresented: Bool
@Binding var selectedItem: Item?
```
### @StateObject - Owned observable object
```swift
@StateObject private var viewModel = MyViewModel()
```
### @ObservedObject - Passed observable object
```swift
@ObservedObject var viewModel: MyViewModel
```
### @EnvironmentObject - Shared via environment
```swift
@EnvironmentObject var settings: AppSettings
```
### @AppStorage - UserDefaults backed
```swift
@AppStorage("username") private var username = ""
```
## Best Practices
1. **Use @StateObject for ownership**: When the view creates the object
2. **Use @ObservedObject for injection**: When the object is passed in
3. **Keep views small**: Extract components
4. **Use previews**: Test different states
5. **Mark async operations**: Use @MainActor for ViewModels
6. **Handle errors gracefully**: Show user-friendly messages
## Related Skills
- `macos-entitlements-generator` - App capabilities
- `macos-notarization-workflow` - Distribution
- `xctest-ui-test-generator` - UI testing
## Related Agents
- `swiftui-macos-expert` - SwiftUI expertise
- `desktop-ux-analyst` - UX patternsRelated Skills
color-palette-generator
Generate accessible color palettes with WCAG compliance
tracing-schema-generator
Generate distributed tracing schemas for OpenTelemetry with Jaeger/Zipkin integration
metrics-schema-generator
Generate metrics schemas for Prometheus, OpenTelemetry, and Grafana dashboards
log-schema-generator
Generate structured logging schemas with correlation ID patterns and ELK/Splunk integration
load-test-generator
Generate load test scripts for k6, Locust, and Gatling from OpenAPI specs
graphql-schema-generator
Generate GraphQL schemas from data models with resolver stubs and federation support
docs-site-generator
Generate documentation sites using Docusaurus, MkDocs, or VuePress
dependency-graph-generator
Generate module dependency graphs with circular dependency detection and coupling metrics
dashboard-generator
Generate monitoring dashboards for Grafana and DataDog with alert integration
c4-diagram-generator
Specialized skill for generating C4 model architecture diagrams. Supports Structurizr DSL, PlantUML, and Mermaid formats with multi-level abstraction (Context, Container, Component, Code).
adr-generator
Specialized skill for generating and managing Architecture Decision Records (ADRs). Supports Nygard, MADR, and custom templates with auto-numbering, linking, and status management.
typespec-sdk-generator
Microsoft TypeSpec-based API and SDK generation