swiftui-ui-patterns
Installation
SKILL.md
SwiftUI UI Patterns
Overview
Most SwiftUI screens are assembled from the same few decisions: where each piece of state lives, how the user moves between screens, how modal presentations are triggered, and what the view shows while data is loading, missing or broken. Getting these right once makes the rest of the view code short. This skill gives one pattern for each decision, with the API availability checked against Apple's documentation, and two complete examples to copy the shape from. It deliberately leaves out component catalogues: for a single control, read its documentation page.
Instructions
1. Look before writing
- Deployment target decides which column of the tables below applies. Find it in the project settings or
Package.swift(platforms:). - House style. Search for the nearest existing screen and match it:
grep -rnE "NavigationStack|NavigationSplitView|TabView|\.sheet\(" --include="*.swift" .Do not introduce a second navigation or state style into a project that already has one. - Xcode version. With Xcode 27 or later
@Stateis a macro that creates a class-typed initial value once. With Xcode 26 or earlier it is a property wrapper, and the initial-value expression runs every time the view is initialised (only the first result is kept). On older Xcode, keep model initialisers cheap or create the model in.task.
2. Decide who owns each piece of state
Pick the owner first, then the declaration follows.