swiftui-core
SwiftUI Core Patterns
Modern SwiftUI patterns for views, navigation, state, toolbars, and text editing.
Critical Constraints
- ❌
NavigationView→ ✅NavigationSplitView(sidebar/detail) orNavigationStack(push/pop) - ❌
@StateObject→ ✅@Statewith@Observableclasses (macOS 14+) - ❌
@ObservedObject→ ✅ direct property or@Bindablefor bindings - ❌
@EnvironmentObject→ ✅@Environmentwith custom key - ❌
toolbar { }without IDs for customizable toolbars → ✅toolbar(id:)withToolbarItem(id:) - ❌ Old
.searchablewithout behavior → ✅ Add.searchToolbarBehavior(.minimize)for space efficiency - ❌ Plain
StringinTextEditorfor rich text → ✅ UseAttributedStringbinding
Reference Index
| File | When to Use |
|---|---|
references/toolbars.md |
Customizable toolbars, search integration, spacers, transitions |
references/text-editing.md |
TextEditor + AttributedString, selection, formatting toolbar |
references/attributed-string.md |
AttributedString API, text alignment, line height, writing direction |
Navigation Patterns
Sidebar + Detail (macOS preferred)
NavigationSplitView {
List(selection: $selectedItem) {
ForEach(items) { item in
NavigationLink(value: item) { Label(item.name, systemImage: item.icon) }
}
}
.navigationTitle("Items")
} detail: {
if let selectedItem {
DetailView(item: selectedItem)
} else {
ContentUnavailableView("Select an item", systemImage: "sidebar.left")
}
}
Push Navigation (iOS preferred)
NavigationStack(path: $path) {
List(items) { item in
NavigationLink(value: item) { Text(item.name) }
}
.navigationDestination(for: Item.self) { item in
DetailView(item: item)
}
}
State Management Quick Reference
| Need | macOS 14+ / iOS 17+ | Older targets |
|---|---|---|
| View owns mutable state | @State |
@State (value) / @StateObject (object) |
| View receives object | plain property | @ObservedObject |
| View needs binding | @Bindable var model |
@ObservedObject var model |
| Shared via environment | @Environment(\.key) |
@EnvironmentObject |
| View-local value | @State private var |
@State private var |
Common Mistakes & Fixes
| Mistake | Fix |
|---|---|
NavigationView { } |
NavigationSplitView { } detail: { } or NavigationStack { } |
.toolbar { ToolbarItem { } } for customizable |
.toolbar(id: "myToolbar") { ToolbarItem(id: "action") { } } |
Using NavigationLink(destination:) |
Use NavigationLink(value:) + .navigationDestination(for:) |
TextField for rich text |
TextEditor(text: $attributedString, selection: $selection) |
.sheet(isPresented:) without transition |
Add .matchedTransitionSource + .navigationTransition(.zoom) |
References
More from makgunay/claude-swift-skills
macos-app-structure
macOS application architecture patterns covering App protocol (@main), Scene types (WindowGroup, Window, Settings, MenuBarExtra), multi-window management, NSApplicationDelegateAdaptor for AppKit lifecycle hooks, Info.plist configuration (LSUIElement for menu bar apps, NSAccessibilityUsageDescription), entitlements for sandbox/hardened runtime, and project structure conventions. Use when scaffolding a new macOS app, configuring scenes and windows, setting up menu bar apps, or resolving macOS-specific lifecycle issues. Corrects the common LLM mistake of generating iOS-only app structures.
31appkit-bridge
Bridging AppKit components into SwiftUI macOS apps. Covers NSViewRepresentable and NSViewControllerRepresentable protocols for hosting AppKit views in SwiftUI, NSHostingView/NSHostingController for hosting SwiftUI in AppKit, NSPanel for floating windows, NSWindow configuration (styleMask, level, collectionBehavior), responder chain integration, NSEvent monitoring (global and local), NSAnimationContext for AppKit animations, NSPopover, NSStatusItem for menu bar, and NSGlassEffectView for AppKit Liquid Glass. Use when SwiftUI lacks a native equivalent, building floating panels, custom window chrome, or integrating legacy AppKit components.
15global-hotkeys
System-wide keyboard shortcut registration on macOS using NSEvent monitoring (simple, app-level) and Carbon EventHotKey API (reliable, system-wide). Covers NSEvent.addGlobalMonitorForEvents and addLocalMonitorForEvents, CGEvent tap for keystroke simulation, Carbon RegisterEventHotKey for system-wide hotkeys, modifier flag handling (.deviceIndependentFlagsMask), common key code mappings, debouncing, Accessibility permission requirements (AXIsProcessTrusted), and SwiftUI .onKeyPress for in-app shortcuts. Use when implementing global keyboard shortcuts, hotkey-triggered panels, or system-wide key event monitoring.
11swiftui-webkit
Native SwiftUI WebKit integration with the new WebView struct and WebPage observable class. Covers WebView creation from URLs, WebPage for navigation control and state management, JavaScript execution (callJavaScript with arguments and content worlds), custom URL scheme handlers, navigation management (load, reload, back/forward), navigation decisions, text search (findNavigator), content capture (snapshots, PDF generation, web archives), and configuration (data stores, user agents, JS permissions). Use when embedding web content in SwiftUI apps instead of the old WKWebView + UIViewRepresentable/NSViewRepresentable bridge pattern. This is a brand new API — do NOT use the old WKWebView wrapping approach.
10liquid-glass
Comprehensive guide to Apple's Liquid Glass design system introduced in macOS 26, iOS 26, and across all Apple platforms. Covers SwiftUI (.glassEffect(), GlassEffectContainer, .interactive(), .tint(), glassEffectID morphing, .buttonStyle(.glass), .buttonStyle(.glassProminent), glassEffectUnion), AppKit (NSGlassEffectView, NSGlassEffectContainerView), UIKit (UIGlassEffect, UIGlassContainerEffect, UIScrollEdgeEffect), and WidgetKit (accented rendering mode, widgetAccentable). Use whenever building UI with the new Apple design language, adopting glass effects, styling buttons or toolbars, or creating modern macOS/iOS interfaces. Always consult this skill when asked about new Apple design.
10tech-stack-validator
Validates and recommends technology stacks for native macOS/iOS app projects against PRD and architecture requirements. Reads the PRD and architecture documents (or gathers requirements interactively), then systematically checks every technology choice for: OS version availability, framework capability gaps, performance feasibility, distribution compatibility (sandbox vs direct), API deprecation risks, dependency conflicts, and timeline realism for the team size. Produces a structured validation report with go/no-go verdicts, risk flags, and alternative recommendations. Use when user says things like 'validate my tech stack', 'check if this architecture works', 'what should I build this with', 'is SwiftData the right choice', 'can I ship this on the App Store', 'review my architecture', or before starting implementation of any PRD. Also use when migrating between tech stacks or evaluating whether to adopt a new framework.
9