swiftui
Skill2 starsChanged 3 months agoMITView on GitHub
SwiftUI mental model (identity, lifetime, dependencies), performance rules for views/List/Table, and the iOS 26 / macOS Tahoe Liquid Glass design APIs. Use when writing or reviewing SwiftUI code, debugging state loss, broken animations, slow updates/hangs/hitches, or adopting the new design system.
10 other projects use a version of this.
Adopted by
Most recently taken up by
- turkeryildirim/ai-skillstheir own version, first seen Nov 1, 2026
- sreejithraman/SreeStacktheir own version, first seen Oct 27, 2026
- g-cqd/skillstheir own version, first seen Oct 23, 2026
- caglarbaranbora/Apple-Agent-Kittheir own version, first seen Oct 13, 2026
- FradSer/skillstheir own version, first seen Oct 13, 2026
- G1Joshi/Agent-Skillstheir own version, first seen Oct 13, 2026
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- Prisma-Labs-Dev/apple-skills★ 336same name
- G1Joshi/Agent-Skills★ 15same name
- FradSer/skills★ 4same name
- moasq/ios-dev-agent★ 4same name
- turkeryildirim/ai-skills★ 4same name
- g-cqd/skills★ 2same name
- caglarbaranbora/Apple-Agent-Kit★ 1same name
- sreejithraman/SreeStack★ 1same name
- Chaeguevara/Skills★ 0same name
- Fe2-O3/swift-field-guide★ 0same 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 repository6 other files it gives its agents.
- app-growthSkill
- app-reviewSkill
- deslopSkill
- ghostwriteSkill
- heavy-workSkill
- ship-featureSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
When SwiftUI looks at code it sees three things:
- Very specific: line 34
Keep
bodycheap: No data filtering, sorting, expensive string interpolation, bundle lookups, or heap allocation in body. - Very specific: line 37
Debugging re-renders: call Self._printChanges() in body (or via expression Self._printChanges() at an LLDB breakpoint) to see why body ran.
- Distinctive: line 44
Keep identifiers cheap to compute.
“Common” is measured: kept by at least 6 in 10 of the 9 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
Distilled from three WWDC sessions:
- Demystify SwiftUI (WWDC21) — identity, lifetime, dependencies
- Demystify SwiftUI performance (WWDC23) — dependency graph, slow updates, List/Table
- Build a SwiftUI app with the new design (WWDC25) — Liquid Glass APIs
Core mental model
When SwiftUI looks at code it sees three things:
- Identity — how SwiftUI recognizes elements as the same or distinct across updates.
- Lifetime — the duration of an identity. View values (the structs) are ephemeral, recreated on every body evaluation; identity is what persists.
- Dependencies — the inputs (properties, @State, @Binding, @Environment, observable objects) that, when changed, require a new body. Views + dependencies form a graph, not a tree; SwiftUI re-evaluates only invalidated views.
The single most important consequence: @State/@StateObject storage is tied to identity. When identity changes, state is destroyed and recreated from initial values. Unexpected state loss, broken transitions, and flashing UI are almost always identity bugs.
Identity rules
- Explicit identity:
ForEach(items)(viaIdentifiable),ForEach(items, id: \.someKey),.id(_:). Structural identity: type + position in the hierarchy — everyif/elsebranch is a distinct view with distinct identity. - Identifiers must be stable (never generate in a computed property —
var id: UUID { UUID() }is a classic bug; don't use array indices) and unique (one ID per view; a non-unique key likenamedrops rows and breaks animations). Use database IDs or stable properties of the data. - Branch vs. modifier:
if expired { content.opacity(0.3) } else { content }creates two identities — state resets and views fade in/out instead of animating in place. Prefer a single view with an inert modifier:content.opacity(expired ? 0.3 : 1). Inert modifiers (opacity 1, padding 0,transformEnvironment, etc.) are cheap and get pruned. Before writing a branch, ask: is this two different views, or two states of one view? - Avoid
AnyViewwherever possible. It erases the type structure SwiftUI uses for identity, hurts performance, hides compiler diagnostics, and hurts readability. In helper functions that return different view types per branch, apply@ViewBuilderto the function and use plainif/switchinstead of wrapping inAnyView.
Performance rules
Slow updates cause hangs (delayed response) and hitches (skipped animation frames). Common causes and fixes:
- Keep
bodycheap. No data filtering, sorting, expensive string interpolation, bundle lookups, or heap allocation in body. Move work to the model or an async.task. - Don't do synchronous expensive work in
@StateObject/@Stateinitializers (e.g. fetching in an object'sinitthat's lazily hit from body). Make it async and load in.task { await ... }. - Scope dependencies tightly. A view whose value contains a whole
Dogre-renders when any dog property changes. Extract subviews that take only what they render (ScalableDogImage(image:)not(dog:)). TheObservablemacro also auto-narrows dependencies to properties actually read. Use judgment — not every dependency needs extraction. - Debugging re-renders: call
Self._printChanges()in body (or viaexpression Self._printChanges()at an LLDB breakpoint) to see why body ran.@self= view value changed; a named property = that dynamic property changed. Underscore API — debug only, never ship it.
List and Table
List/Table gather all row identifiers eagerly, up front. Rows are built on demand, but only if SwiftUI can count rows without building content — so each ForEach element must resolve to a constant number of views:
- No
ifinside ForEach content to filter rows (element count becomes 0-or-1 → all rows must be built). NoAnyView(count unknown). Filter the data, and do the filtering in the model (cached), not inline in body (linear cost on every evaluation). - Keep identifiers cheap to compute; row count = elements × views-per-element, and views-per-element must be constant.
- Flatten nested
ForEach— except dynamic sections (ForEachof sections containingForEachof rows), which SwiftUI understands and keeps fast. - Table: prefer the streamlined
Table { ... ForEach(collection) }initializer (back-deploys); note iOS 17 changed row identity to come from the ForEach data, notTableRowvalues.
Liquid Glass / new design (Xcode 26, iOS 26, macOS Tahoe)
Building with the Xcode 26 SDK updates most standard components automatically. Key APIs:
- App structure: floating glass sidebar on
NavigationSplitView;backgroundExtensionEffect()extends hero images under the sidebar without clipping. Tab bar floats and can minimize on scroll:.tabBarMinimizeBehavior(.onScrollDown); put controls above it with.tabViewBottomAccessory { }and readtabViewBottomAccessoryPlacementfrom the environment to adapt when collapsed. - Sheets/presentations: partial-height sheets get an inset glass background — remove custom
presentationBackgrounds. Sheets/menus/popovers can morph out of their presenting button via zoom-transition source/destination. - Toolbars: items sit on floating glass and auto-group; use
ToolbarSpacer(.fixed)/.flexibleto control grouping,.sharedBackgroundVisibility(.hidden)to detach an item,.badge(_:)on toolbar items. Icons are monochrome by default — tint only to convey meaning. Remove any custom backgrounds/darkening behind bars; tune the scroll edge effect withscrollEdgeEffectStyle. - Search:
.searchableonNavigationSplitView→ top-trailing field (Mac/iPad) / bottom field (iPhone);.searchToolbarBehaviorfor the minimized button variant. Dedicated search tab: give the tab a.searchrole and put.searchableon theTabView. - Controls: bordered buttons are capsules;
.buttonBorderShapeto override; extra-large size and.glass/.glassProminentbutton styles exist. Sliders support tick marks (step or manualticksclosure) andneutralValuefor non-leading fill start. UseConcentricRectangle/container-concentric corners to match container curvature. - Custom glass:
.glassEffect()(default capsule; pass a shape to customize;.tintfor meaning;.interactivefor touch response). Multiple glass elements must share aGlassEffectContainerto sample each other correctly; addglassEffectID(_:in:)with aNamespacefor fluid morphing between states. - Adoption checklist: build with Xcode 26, audit backgrounds behind sheets/toolbars and remove them, then add custom glass only for signature elements.
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.

