swiftui-ui-patterns
Skill2 starsChanged 40 days agoMITView on GitHub
Best practices and example-driven guidance for building SwiftUI views and components, including navigation hierarchies, custom view modifiers, and responsive layouts with stacks and grids. Use when creating or refactoring SwiftUI UI, designing tab architecture with TabView, composing screens with VStack/HStack, managing @State or @Binding, building declarative iOS interfaces, or needing component-specific patterns and examples.
21 other projects use a version of this, 15 of them edited.
Adopted by
Most recently taken up by
- lingyired/status-trioword for word, first seen Nov 8, 2026
- MMACABRE/SKILLSedited, first seen Nov 8, 2026
- VelimirMueller/claude-skillsedited, first seen Nov 1, 2026
- VelimirMueller/ai-development-skillsedited, first seen Nov 1, 2026
- deonmenezes/mobile-app-skillword for word, first seen Nov 1, 2026
- spokvulcan/claude-code-build-ios-appsedited, first seen Oct 17, 2026
Used with
Projects with it also use app-store-changelog.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
patrickserranoSkillapp-store-changelog
Create user-facing App Store release notes from git history. Use when asked to generate release changelog, App Store "What's New" text, or release notes based on git tags.
Also in 4 projects that use this
Other versions21 projects use a version of this.
Word for word · 5
- Dimillian/Skills★ 4k100% same
- lingyired/status-trio★ 1.8k100% same
- deonmenezes/mobile-app-skill★ 4100% same
- Adhamxon/claude-code-skills★ 2100% same
- henryhudson/swift-claude-skills★ 1100% same
Edited · 15
- openai/plugins★ 7.8k95% same
- AFK-surf/OpenBridge★ 43068% same
- omarshahine/HomeClaw★ 19197% same
- robinebers/skills★ 4895% same
- eugenepyvovarov/mcpbundler-agent-skills-marketplace★ 1268% same
- 199-biotechnologies/swiftui-claude-skills★ 768% same
- VelimirMueller/ai-development-skills★ 799% same
- VelimirMueller/claude-skills★ 799% same
- ParkerRex/Skills★ 279% same
- spokvulcan/claude-code-build-ios-apps★ 297% same
5 more not listed
Wrote their own version · 1
- ai4brands-design/claude-skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository28 other files it gives its agents.
- broSkill
- codebase-designSkill
- diagnosing-bugsSkill
- domain-modelingSkill
- grill-with-docsSkill
- implementSkill
- implement-specSkill
- improve-codebase-architectureSkill
- iphone-duo-adaptSkill
- openai-docsSkill
- product-thinkingSkill
- prSkill
- researchSkill
- retroSkill
- setup-matt-pocock-skillsSkill
- swift-concurrency-expertSkill
- swift-concurrencySkill
- swiftui-expert-skillSkill
- swiftui-liquid-glassSkill
- swiftui-performance-auditSkill
- swiftui-proSkill
- swiftui-view-refactorSkill
- tddSkill
- to-specSkill
- to-ticketsSkill
- typesafe-aiSkill
- wayfinderSkill
- wwdc-knowledgeSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. 3 are common, 3 are distinctive, and 11 are very specific to this project.
3
Common
Most of the 16 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 18
If the interaction reveals secondary content by dragging or scrolling the primary content away, read references/scroll-reveal.md before …
- Very specific: line 23
Start with references/app-wiring.md to wire TabView + NavigationStack + sheets.
- Very specific: line 24
Add a minimal AppTab and RouterPath based on the provided skeletons.
- Very specific: line 30
Use modern SwiftUI state (@State, @Binding, @Observable, @Environment) and avoid unnecessary view models.
- Very specific: line 31
If the deployment target includes iOS 16 or earlier and cannot use the Observation API introduced in iOS 17, fall back to ObservableObject …
- Common: line 32
Prefer composition; keep views small and focused.
- Very specific: line 33
Use async/await with .task and explicit loading/error states.
- Very specific: line 34
Keep shared app services in @Environment, but prefer explicit initializer injection for feature-local dependencies and models.
- Distinctive: line 35
Prefer the newest SwiftUI API that fits the deployment target and call out the minimum OS whenever a pattern depends on it.
- Common: line 37
Follow the project's formatter and style guide.
- Very specific: line 38
Sheets: Prefer .sheet(item:) over .sheet(isPresented:) when state represents a selected model.
- Distinctive: line 39
Scroll-driven reveals: Prefer deriving a normalized progress value from scroll offset and driving the visual state from that single source …
- Distinctive: line 43
Use the narrowest state tool that matches the ownership model:
- Very specific: line 80
Add previews for the primary and secondary states, then add accessibility labels or identifiers when the UI is interactive.
- Very specific: line 85
Use references/components-index.md as the entry point.
- Common: line 94
Keep it short and actionable.
- Very specific: line 95
Update references/components-index.md with the new entry.
“Common” is measured: kept by at least 6 in 10 of the 16 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SwiftUI UI Patterns
Quick start
Choose a track based on your goal:
Existing project
- Identify the feature or screen and the primary interaction model (list, detail, editor, settings, tabbed).
- Find a nearby example in the repo with
rg "TabView\("or similar, then read the closest SwiftUI view. - Apply local conventions: prefer SwiftUI-native state, keep state local when possible, and use environment injection for shared dependencies.
- Choose the relevant component reference from
references/components-index.mdand follow its guidance. - If the interaction reveals secondary content by dragging or scrolling the primary content away, read
references/scroll-reveal.mdbefore implementing gestures manually. - Build the view with small, focused subviews and SwiftUI-native data flow.
New project scaffolding
- Start with
references/app-wiring.mdto wire TabView + NavigationStack + sheets. - Add a minimal
AppTabandRouterPathbased on the provided skeletons. - Choose the next component reference based on the UI you need first (TabView, NavigationStack, Sheets).
- Expand the route and sheet enums as new screens are added.
General rules to follow
- Use modern SwiftUI state (
@State,@Binding,@Observable,@Environment) and avoid unnecessary view models. - If the deployment target includes iOS 16 or earlier and cannot use the Observation API introduced in iOS 17, fall back to
ObservableObjectwith@StateObjectfor root ownership,@ObservedObjectfor injected observation, and@EnvironmentObjectonly for truly shared app-level state. - Prefer composition; keep views small and focused.
- Use async/await with
.taskand explicit loading/error states. For restart, cancellation, and debouncing guidance, readreferences/async-state.md. - Keep shared app services in
@Environment, but prefer explicit initializer injection for feature-local dependencies and models. For root wiring patterns, readreferences/app-wiring.md. - Prefer the newest SwiftUI API that fits the deployment target and call out the minimum OS whenever a pattern depends on it.
- Maintain existing legacy patterns only when editing legacy files.
- Follow the project's formatter and style guide.
- Sheets: Prefer
.sheet(item:)over.sheet(isPresented:)when state represents a selected model. Avoidif letinside a sheet body. Sheets should own their actions and calldismiss()internally instead of forwardingonCancel/onConfirmclosures. - Scroll-driven reveals: Prefer deriving a normalized progress value from scroll offset and driving the visual state from that single source of truth. Avoid parallel gesture state machines unless scroll alone cannot express the interaction.
State ownership summary
Use the narrowest state tool that matches the ownership model:
| Scenario | Preferred pattern |
| Local UI state owned by one view | @State |
| Child mutates parent-owned value state | @Binding |
| Root-owned reference model on iOS 17+ | @State with an @Observable type |
Child reads or mutates an injected @Observable model on iOS 17+ | Pass it explicitly as a stored property |
| Shared app service or configuration | @Environment(Type.self) |
| Legacy reference model on iOS 16 and earlier | @StateObject at the root, @ObservedObject when injected |
Choose the ownership location first, then pick the wrapper. Do not introduce a reference model when plain value state is enough.
Cross-cutting references
references/navigationstack.md: navigation ownership, per-tab history, and enum routing.references/sheets.md: centralized modal presentation and enum-driven sheets.references/deeplinks.md: URL handling and routing external links into app destinations.references/app-wiring.md: root dependency graph, environment usage, and app shell wiring.references/async-state.md:.task,.task(id:), cancellation, debouncing, and async UI state.references/previews.md:#Preview, fixtures, mock environments, and isolated preview setup.references/performance.md: stable identity, observation scope, lazy containers, and render-cost guardrails.
Anti-patterns
- Giant views that mix layout, business logic, networking, routing, and formatting in one file.
- Multiple boolean flags for mutually exclusive sheets, alerts, or navigation destinations.
- Live service calls directly inside
body-driven code paths instead of view lifecycle hooks or injected models/services. - Reaching for
AnyViewto work around type mismatches that should be solved with better composition. - Defaulting every shared dependency to
@EnvironmentObjector a global router without a clear ownership reason.
Workflow for a new SwiftUI view
- Define the view's state, ownership location, and minimum OS assumptions before writing UI code.
- Identify which dependencies belong in
@Environmentand which should stay as explicit initializer inputs. - Sketch the view hierarchy, routing model, and presentation points; extract repeated parts into subviews. For complex navigation, read
references/navigationstack.md,references/sheets.md, orreferences/deeplinks.md. Build and verify no compiler errors before proceeding. - Implement async loading with
.taskor.task(id:), plus explicit loading and error states when needed. Readreferences/async-state.mdwhen the work depends on changing inputs or cancellation. - Add previews for the primary and secondary states, then add accessibility labels or identifiers when the UI is interactive. Read
references/previews.mdwhen the view needs fixtures or injected mock dependencies. - Validate with a build: confirm no compiler errors, check that previews render without crashing, ensure state changes propagate correctly, and sanity-check that list identity and observation scope will not cause avoidable re-renders. Read
references/performance.mdif the screen is large, scroll-heavy, or frequently updated. For common SwiftUI compilation errors — missing@Stateannotations, ambiguousViewBuilderclosures, or mismatched generic types — resolve them before updating callsites. If the build fails: read the error message carefully, fix the identified issue, then rebuild before proceeding to the next step. If a preview crashes, isolate the offending subview, confirm its state initialisation is valid, and re-run the preview before continuing.
Component references
Use references/components-index.md as the entry point. Each component reference should include:
- Intent and best-fit scenarios.
- Minimal usage pattern with local conventions.
- Pitfalls and performance notes.
- Paths to existing examples in the current repo.
Adding a new component reference
- Create
references/<component>.md. - Keep it short and actionable; link to concrete files in the current repo.
- Update
references/components-index.mdwith the new entry.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

