SwiftUI macOS View Builder
Generate production-quality SwiftUI views tailored for macOS, with proper AppKit idioms, keyboard navigation, and platform-native feel.
Prompt Template
You are an expert SwiftUI developer who builds polished macOS apps. Generate a production-ready SwiftUI view for macOS. **View Purpose:** [e.g., "A settings window with sidebar navigation and multiple panes"] **Data It Displays/Edits:** [describe the data model] **Interactions Required:** - [e.g., inline editing, drag & drop, context menus] - [e.g., keyboard shortcuts, toolbar actions] - [e.g., search/filter, sorting] **Window Type:** [main window / sheet / popover / settings / menu bar panel] **Design Reference:** [optional — describe a native macOS app with similar UI, e.g., "like Finder's column view" or "like System Settings sidebar"] Requirements: 1. Use **macOS-native** patterns — NavigationSplitView, Table, Form with proper grouping 2. Add **keyboard shortcuts** (.keyboardShortcut) for common actions 3. Include **context menus** where appropriate 4. Support **dark mode** properly (use system colors) 5. Add **toolbar** items following macOS HIG 6. Handle **empty states** gracefully 7. Include **accessibility** labels 8. Add inline comments explaining macOS-specific decisions 9. Use **@Observable** (macOS 14+) or **ObservableObject** (macOS 13) 10. Show the **Preview** with sample data
Example Output
import SwiftUI
struct ProjectListView: View {
@State private var projects: [Project] = Project.samples
@State private var selected: Project.ID?
@State private var searchText = ""
@State private var sortOrder = [KeyPathComparator(\\Project.dateModified, order: .reverse)]
@State private var showingNewProject = false
var filtered: [Project] {
let sorted = projects.sorted(using: sortOrder)
guard !searchText.isEmpty else { return sorted }
return sorted.filter { $0.name.localizedCaseInsensitiveContains(searchText) }
}
var body: some View {
Table(filtered, selection: $selected, sortOrder: $sortOrder) {
TableColumn("Name", value: \\.name) { project in
Label(project.name, systemImage: "folder.fill")
.accessibilityLabel("Project: \(project.name)")
}
.width(min: 150, ideal: 250)
TableColumn("Status", value: \\.status.rawValue) { project in
StatusBadge(status: project.status)
}
.width(80)
TableColumn("Modified", value: \\.dateModified) { project in
Text(project.dateModified, style: .relative)
.foregroundStyle(.secondary)
}
.width(100)
}
.contextMenu(forSelectionType: Project.ID.self) { ids in
Button("Open") { /* ... */ }
Button("Duplicate") { /* ... */ }
Divider()
Button("Delete", role: .destructive) { /* ... */ }
}
.searchable(text: $searchText, prompt: "Filter projects")
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: { showingNewProject = true }) {
Label("New Project", systemImage: "plus")
}
.keyboardShortcut("n")
}
}
.overlay {
if filtered.isEmpty {
ContentUnavailableView.search(text: searchText)
}
}
.navigationTitle("Projects")
}
}
Tips for Best Results
- 💡Mention which macOS version you target — Table and NavigationSplitView require macOS 13+
- 💡Reference a native Apple app if you want a specific look and feel
- 💡Specify if you need AppKit interop (NSViewRepresentable) for features SwiftUI doesn't cover yet
- 💡Ask for the Preview struct too — it makes iteration in Xcode much faster
Related Prompts
macOS App Architecture Planner
Design a clean, production-ready architecture for a native macOS app using SwiftUI, including data flow, persistence, and system integration.
macOS Menu Bar App Generator
Build a complete macOS menu bar (status bar) app with SwiftUI, including popover UI, keyboard shortcuts, and launch-at-login support.
macOS Document-Based App Builder
Create a native macOS document-based app with SwiftUI, supporting custom file formats, autosave, versioning, and iCloud Documents.