SwiftUI Programming Skill
Skill18 starsChanged 56 days agoMITView on GitHub
Use when work involves SwiftUI view composition, state and Observation ownership, navigation, adaptive layout, toolbars, forms, SF Symbols, accessibility, previews, or SwiftUI-specific performance. Do not use for UIKit/AppKit-only work, general Swift language questions, or architecture and performance work that does not involve SwiftUI.
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- app-intents-widgetsSkill
- Cross-Platform App Development SkillSkill
- iOS Accessibility SkillSkill
- iOS Animation Graphics SkillSkill
- iphone-duo-designSkill
- Memory Leak Diagnosis SkillSkill
- swift-concurrency-migrationSkill
- swiftdata-core-data-migrationsSkill
- Swift Modern Architecture SkillSkill
- Swift Performance Optimization SkillSkill
- SpeechAnalyzer Framework ExpertSkill
- Swift Unit Testing SkillSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. About 0 are common, 10 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
Add accessibility and Dynamic Type while composing the view.
- Very specific: line 35
Use @State for view-owned value state.
- Very specific: line 38
Use @Environment for dependencies intentionally shared through a subtree.
- Very specific: line 39
Keep UI-observed mutable models on @MainActor unless their isolation is deliberately designed otherwise.
- Distinctive: line 40
Do not copy derived state into another mutable property.
- Very specific: line 67
Prefer flexible frames, stacks, grids, ViewThatFits, and size classes.
- Distinctive: line 69
Use semantic colors and text styles.
- Distinctive: line 70
Treat iPad multitasking, macOS window resizing, tvOS focus, watchOS glanceability, and visionOS volumes as distinct capabilities.
- Very specific: line 75
Prefer NavigationStack at its supported minimum.
- Distinctive: line 76
Keep destination construction consistent: every destination receives the selected value it requires.
- Very specific: line 77
Use semantic toolbar placements such as .primaryAction, .confirmationAction, and .cancellationAction where they express intent across …
- Distinctive: line 78
Do not use iOS-only placements or modifiers in an ungated all-platform view.
- Very specific: line 84
Prefer Button, Toggle, TextField, Label, and other semantic controls.
- Distinctive: line 86
Keep separate interactive controls as separate accessibility elements.
- Very specific: line 87
Use semantic fonts (.body, .headline) or @ScaledMetric.
- Very specific: line 96
Use SwiftUI's .equatable() or EquatableView only after measurement and only when equality fully represents visible output.
- Distinctive: line 101
Verify each symbol exists for the deployment target and choose a fallback for newer symbols.
- Distinctive: line 102
Use rendering modes and symbol effects only at their documented availability.
- Distinctive: line 111
When a requested example spans architecture, accessibility, performance, or platform-specific behavior, keep this skill focused on the …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SwiftUI Programming Skill
Build SwiftUI interfaces that are correct for the user's declared platforms and deployment targets. Ask for those targets when an API choice depends on them; never assume the newest SDK is deployable.
Supported baseline
The primary examples use Xcode 15, Swift 5.9, and iOS/iPadOS 17 or macOS 14. SwiftUI itself supports older systems, but newer APIs need explicit availability handling:
| Need | Preferred API | Minimum | Compatibility path |
| Stack navigation | NavigationStack | iOS 16, macOS 13, tvOS 16, watchOS 9 | NavigationView remains valid for earlier targets |
| Observation | @Observable | iOS 17, macOS 14, tvOS 17, watchOS 10 | ObservableObject and @StateObject remain supported |
| Toolbars | .toolbar | iOS 14, macOS 11, tvOS 14, watchOS 7 | Put controls in the view hierarchy on earlier targets |
| Modern change handling | zero- or two-parameter onChange | iOS 17, macOS 14, tvOS 17, watchOS 10 | Use the one-parameter overload on earlier targets |
APIs from the OS 27 development cycle are beta material relative to the stable Xcode 26.6 toolchain. Discuss them only when explicitly requested, label them beta, and provide stable fallbacks plus #available gates.
Workflow
- Record Swift, Xcode, and every platform minimum.
- Choose semantic system controls before custom controls.
- Define state ownership and a stable identity model.
- Choose navigation and layout from capabilities, not device-name guesses.
- Add accessibility and Dynamic Type while composing the view.
- Compile at the oldest supported targets; test large accessibility sizes and relevant input methods.
- Profile before adding performance-specific wrappers or caches.
State and Observation
- Use
@Statefor view-owned value state. - For a view-owned
@Observablereference, store it in@Stateso SwiftUI owns its lifetime. - Pass an injected observable model as a plain property when the view only reads it. Create
@Bindablelocally when the view needs bindings. - Use
@Environmentfor dependencies intentionally shared through a subtree. - Keep UI-observed mutable models on
@MainActorunless their isolation is deliberately designed otherwise. - Do not copy derived state into another mutable property. Prefer a computed property.
import Observation
import SwiftUI
@MainActor
@Observable
final class ProfileModel {
var displayName = ""
}
struct ProfileEditor: View {
@State private var model = ProfileModel()
var body: some View {
@Bindable var model = model
TextField("Display name", text: $model.displayName)
}
}For iOS 16 and earlier, use ObservableObject with @StateObject for view ownership and @ObservedObject for injection. That is a compatibility decision, not an anti-pattern.
Composition and layout
- Extract subviews around meaningful responsibility, reuse, or independent state—not to force a presumed redraw boundary.
- Prefer flexible frames, stacks, grids,
ViewThatFits, and size classes. UseGeometryReaderonly when the child genuinely needs the proposed size. - Respect safe areas unless the visual treatment deliberately extends under system UI.
- Use semantic colors and text styles; avoid fixed text heights and one-line truncation for user content.
- Treat iPad multitasking, macOS window resizing, tvOS focus, watchOS glanceability, and visionOS volumes as distinct capabilities.
Navigation and toolbars
- Model destinations with stable,
Hashableroute data when navigation is state-driven. - Prefer
NavigationStackat its supported minimum. UseNavigationSplitViewfor genuinely multi-column interfaces, with a compact fallback. - Keep destination construction consistent: every destination receives the selected value it requires.
- Use semantic toolbar placements such as
.primaryAction,.confirmationAction, and.cancellationActionwhere they express intent across platforms. - Do not use iOS-only placements or modifiers in an ungated all-platform view.
See the complete toolbar example and prompt scenarios.
Accessibility and Dynamic Type
- Prefer
Button,Toggle,TextField,Label, and other semantic controls. - Label icon-only controls with their purpose. Hints describe the result of an action, not the gesture.
- Keep separate interactive controls as separate accessibility elements.
- Use semantic fonts (
.body,.headline) or@ScaledMetric; do not claim that a fixed.system(size:)font scales. - Preserve alternatives to color, adequate interactive sizes and spacing, Reduce Motion, and Differentiate Without Color.
Performance
- First measure with Instruments on a release build and representative hardware.
- Give collection elements stable IDs. Never use array offsets as identity for mutable collections.
Listalready creates rows lazily. UseScrollViewplusLazyVStackfor layout/interaction behavior thatListcannot provide, not as a blanket speed upgrade.- A parent body evaluation does not mean every descendant is redrawn on screen. Keep
bodyinexpensive, but do not promise that extracting a view creates an independent render boundary. - Use SwiftUI's
.equatable()orEquatableViewonly after measurement and only when equality fully represents visible output. - Cancel asynchronous work when its owning view disappears or its input changes.
.task(id:)is usually the clearest view-lifetime tool.
SF Symbols
- Verify each symbol exists for the deployment target and choose a fallback for newer symbols.
- Use rendering modes and symbol effects only at their documented availability.
- Give decorative symbols no separate accessibility focus; label icon-only controls at the control level.
Copy-ready examples
- State-driven toggle
- Navigation and semantic toolbar actions
- Example prompts
When a requested example spans architecture, accessibility, performance, or platform-specific behavior, keep this skill focused on the SwiftUI layer and route the other concerns to their dedicated guidance.
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.

