name: swiftui-ui-patterns description: Build or refactor SwiftUI screens with modern state ownership, navigation, sheets, async loading, previews, accessibility, and performance-aware view composition.
SwiftUI UI Patterns
Use this skill when shaping a SwiftUI screen, refactoring view structure, choosing state wrappers, wiring navigation or sheets, or reviewing UI composition before implementation.
References
- Read
references/state-ownership.mdwhen deciding where state lives or which property wrapper to use. - Read
references/navigation-sheets.mdwhen routing, presenting sheets, alerts, popovers, or split navigation. - Read
references/ipad-mac-adaptation.mdwhen screens need iPad, macOS, menu bar, window, keyboard, pointer, or resizing behavior. - Read
references/async-ui-state.mdwhen screens load, refresh, search, debounce, or cancel async work. - Read
references/view-refactor-patterns.mdwhen splitting large views or cleaning computedsome Viewhelpers. - Read
references/previews-performance.mdwhen adding previews, fixtures, list identity, or render-cost checks. - Use
references/output-contract.mdfor final reports.
Prefer existing project conventions. When the app already has a clear architecture, improve inside that architecture instead of introducing a new pattern.
Workflow
- Identify the target screen, primary interaction, deployment target, and existing local patterns.
- Choose the source of truth for state before choosing property wrappers.
- Map navigation and modal presentation as data, using enum or item state for mutually exclusive destinations.
- Pick an adaptive navigation model: tab, stack, sidebar/detail, inspector, or multiwindow.
- Keep resizing, rotation, and multiwindow behavior non-destructive.
- Keep async work cancellable and tied to view lifecycle or explicit user actions.
- Split complex screens into dedicated subview types with small explicit inputs.
- Add previews for important states when the project supports previews.
- Check accessibility, Dynamic Type, and stable identity for lists, grids, and frequently updating views.
- Verify with build, tests, or static checks when safe and relevant.
Guardrails
- Do not add a ViewModel just to mirror local view state.
- Do not bury business logic in
body,.task,.onAppear,.onChange, or button closures. - Do not replace a working project-wide pattern for stylistic reasons.
- Do not use multiple booleans for mutually exclusive sheets, alerts, or navigation destinations.
- Do not create a screen from many large computed
some Viewproperties when dedicated subviews would be clearer. - Do not hide menu, command, or toolbar actions by destroying them for ordinary state changes; disable unavailable actions instead.
- Do not leave document or multiwindow scenes unnamed when the app supports multiple windows.
- Do not silently remove iOS 17 or earlier support when adopting newer Observation or SwiftUI APIs.
Output
Use references/output-contract.md.