claudecode-omc 5.6.7 → 5.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/.local/skills/THIRD_PARTY_LICENSES/AvdLee-SwiftUI-Agent-Skill.LICENSE +21 -0
  2. package/.local/skills/THIRD_PARTY_LICENSES/Dimillian-Skills.LICENSE +21 -0
  3. package/.local/skills/THIRD_PARTY_LICENSES/README.md +36 -0
  4. package/.local/skills/THIRD_PARTY_LICENSES/twostraws-swiftui-agent-skill.LICENSE +21 -0
  5. package/.local/skills/ios-debugger-agent/SKILL.md +51 -0
  6. package/.local/skills/ios-debugger-agent/agents/openai.yaml +4 -0
  7. package/.local/skills/swift-concurrency-expert/SKILL.md +105 -0
  8. package/.local/skills/swift-concurrency-expert/agents/openai.yaml +4 -0
  9. package/.local/skills/swift-concurrency-expert/references/approachable-concurrency.md +63 -0
  10. package/.local/skills/swift-concurrency-expert/references/swift-6-2-concurrency.md +272 -0
  11. package/.local/skills/swift-concurrency-expert/references/swiftui-concurrency-tour-wwdc.md +33 -0
  12. package/.local/skills/swiftui-expert-skill/SKILL.md +162 -0
  13. package/.local/skills/swiftui-expert-skill/references/accessibility-patterns.md +215 -0
  14. package/.local/skills/swiftui-expert-skill/references/animation-advanced.md +403 -0
  15. package/.local/skills/swiftui-expert-skill/references/animation-basics.md +284 -0
  16. package/.local/skills/swiftui-expert-skill/references/animation-transitions.md +326 -0
  17. package/.local/skills/swiftui-expert-skill/references/charts-accessibility.md +135 -0
  18. package/.local/skills/swiftui-expert-skill/references/charts.md +602 -0
  19. package/.local/skills/swiftui-expert-skill/references/focus-patterns.md +299 -0
  20. package/.local/skills/swiftui-expert-skill/references/image-optimization.md +203 -0
  21. package/.local/skills/swiftui-expert-skill/references/latest-apis.md +488 -0
  22. package/.local/skills/swiftui-expert-skill/references/layout-best-practices.md +266 -0
  23. package/.local/skills/swiftui-expert-skill/references/liquid-glass.md +423 -0
  24. package/.local/skills/swiftui-expert-skill/references/list-patterns.md +446 -0
  25. package/.local/skills/swiftui-expert-skill/references/macos-scenes.md +318 -0
  26. package/.local/skills/swiftui-expert-skill/references/macos-views.md +357 -0
  27. package/.local/skills/swiftui-expert-skill/references/macos-window-styling.md +303 -0
  28. package/.local/skills/swiftui-expert-skill/references/performance-patterns.md +403 -0
  29. package/.local/skills/swiftui-expert-skill/references/scroll-patterns.md +293 -0
  30. package/.local/skills/swiftui-expert-skill/references/sheet-navigation-patterns.md +363 -0
  31. package/.local/skills/swiftui-expert-skill/references/state-management.md +388 -0
  32. package/.local/skills/swiftui-expert-skill/references/text-patterns.md +32 -0
  33. package/.local/skills/swiftui-expert-skill/references/trace-analysis.md +295 -0
  34. package/.local/skills/swiftui-expert-skill/references/trace-recording.md +134 -0
  35. package/.local/skills/swiftui-expert-skill/references/view-structure.md +780 -0
  36. package/.local/skills/swiftui-expert-skill/scripts/__pycache__/analyze_trace.cpython-313.pyc +0 -0
  37. package/.local/skills/swiftui-expert-skill/scripts/__pycache__/record_trace.cpython-313.pyc +0 -0
  38. package/.local/skills/swiftui-expert-skill/scripts/analyze_trace.py +301 -0
  39. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__init__.py +1 -0
  40. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/__init__.cpython-313.pyc +0 -0
  41. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/causes.cpython-313.pyc +0 -0
  42. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/correlate.cpython-313.pyc +0 -0
  43. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/events.cpython-313.pyc +0 -0
  44. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/hangs.cpython-313.pyc +0 -0
  45. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/hitches.cpython-313.pyc +0 -0
  46. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/summary.cpython-313.pyc +0 -0
  47. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/swiftui.cpython-313.pyc +0 -0
  48. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/time_profiler.cpython-313.pyc +0 -0
  49. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/xctrace.cpython-313.pyc +0 -0
  50. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/__pycache__/xml_utils.cpython-313.pyc +0 -0
  51. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/causes.py +187 -0
  52. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/correlate.py +179 -0
  53. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/events.py +291 -0
  54. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/hangs.py +108 -0
  55. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/hitches.py +145 -0
  56. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/summary.py +243 -0
  57. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/swiftui.py +195 -0
  58. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/time_profiler.py +135 -0
  59. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/xctrace.py +117 -0
  60. package/.local/skills/swiftui-expert-skill/scripts/instruments_parser/xml_utils.py +224 -0
  61. package/.local/skills/swiftui-expert-skill/scripts/record_trace.py +252 -0
  62. package/.local/skills/swiftui-liquid-glass/SKILL.md +90 -0
  63. package/.local/skills/swiftui-liquid-glass/agents/openai.yaml +4 -0
  64. package/.local/skills/swiftui-liquid-glass/references/liquid-glass.md +280 -0
  65. package/.local/skills/swiftui-performance-audit/SKILL.md +106 -0
  66. package/.local/skills/swiftui-performance-audit/agents/openai.yaml +4 -0
  67. package/.local/skills/swiftui-performance-audit/references/code-smells.md +150 -0
  68. package/.local/skills/swiftui-performance-audit/references/demystify-swiftui-performance-wwdc23.md +46 -0
  69. package/.local/skills/swiftui-performance-audit/references/optimizing-swiftui-performance-instruments.md +29 -0
  70. package/.local/skills/swiftui-performance-audit/references/profiling-intake.md +44 -0
  71. package/.local/skills/swiftui-performance-audit/references/report-template.md +47 -0
  72. package/.local/skills/swiftui-performance-audit/references/understanding-hangs-in-your-app.md +33 -0
  73. package/.local/skills/swiftui-performance-audit/references/understanding-improving-swiftui-performance.md +52 -0
  74. package/.local/skills/swiftui-pro/SKILL.md +108 -0
  75. package/.local/skills/swiftui-pro/agents/openai.yaml +10 -0
  76. package/.local/skills/swiftui-pro/assets/swiftui-pro-icon.png +0 -0
  77. package/.local/skills/swiftui-pro/assets/swiftui-pro-icon.svg +29 -0
  78. package/.local/skills/swiftui-pro/references/accessibility.md +13 -0
  79. package/.local/skills/swiftui-pro/references/api.md +39 -0
  80. package/.local/skills/swiftui-pro/references/data.md +43 -0
  81. package/.local/skills/swiftui-pro/references/design.md +32 -0
  82. package/.local/skills/swiftui-pro/references/hygiene.md +9 -0
  83. package/.local/skills/swiftui-pro/references/navigation.md +14 -0
  84. package/.local/skills/swiftui-pro/references/performance.md +46 -0
  85. package/.local/skills/swiftui-pro/references/swift.md +56 -0
  86. package/.local/skills/swiftui-pro/references/views.md +36 -0
  87. package/.local/skills/swiftui-ui-patterns/SKILL.md +95 -0
  88. package/.local/skills/swiftui-ui-patterns/agents/openai.yaml +4 -0
  89. package/.local/skills/swiftui-ui-patterns/references/app-wiring.md +201 -0
  90. package/.local/skills/swiftui-ui-patterns/references/async-state.md +96 -0
  91. package/.local/skills/swiftui-ui-patterns/references/components-index.md +50 -0
  92. package/.local/skills/swiftui-ui-patterns/references/controls.md +57 -0
  93. package/.local/skills/swiftui-ui-patterns/references/deeplinks.md +66 -0
  94. package/.local/skills/swiftui-ui-patterns/references/focus.md +90 -0
  95. package/.local/skills/swiftui-ui-patterns/references/form.md +97 -0
  96. package/.local/skills/swiftui-ui-patterns/references/grids.md +71 -0
  97. package/.local/skills/swiftui-ui-patterns/references/haptics.md +71 -0
  98. package/.local/skills/swiftui-ui-patterns/references/input-toolbar.md +51 -0
  99. package/.local/skills/swiftui-ui-patterns/references/lightweight-clients.md +93 -0
  100. package/.local/skills/swiftui-ui-patterns/references/list.md +86 -0
  101. package/.local/skills/swiftui-ui-patterns/references/loading-placeholders.md +38 -0
  102. package/.local/skills/swiftui-ui-patterns/references/macos-settings.md +71 -0
  103. package/.local/skills/swiftui-ui-patterns/references/matched-transitions.md +59 -0
  104. package/.local/skills/swiftui-ui-patterns/references/media.md +73 -0
  105. package/.local/skills/swiftui-ui-patterns/references/menu-bar.md +101 -0
  106. package/.local/skills/swiftui-ui-patterns/references/navigationstack.md +159 -0
  107. package/.local/skills/swiftui-ui-patterns/references/overlay.md +45 -0
  108. package/.local/skills/swiftui-ui-patterns/references/performance.md +62 -0
  109. package/.local/skills/swiftui-ui-patterns/references/previews.md +48 -0
  110. package/.local/skills/swiftui-ui-patterns/references/scroll-reveal.md +133 -0
  111. package/.local/skills/swiftui-ui-patterns/references/scrollview.md +87 -0
  112. package/.local/skills/swiftui-ui-patterns/references/searchable.md +71 -0
  113. package/.local/skills/swiftui-ui-patterns/references/sheets.md +155 -0
  114. package/.local/skills/swiftui-ui-patterns/references/split-views.md +72 -0
  115. package/.local/skills/swiftui-ui-patterns/references/tabview.md +114 -0
  116. package/.local/skills/swiftui-ui-patterns/references/theming.md +71 -0
  117. package/.local/skills/swiftui-ui-patterns/references/title-menus.md +93 -0
  118. package/.local/skills/swiftui-ui-patterns/references/top-bar.md +49 -0
  119. package/.local/skills/swiftui-view-refactor/SKILL.md +202 -0
  120. package/.local/skills/swiftui-view-refactor/agents/openai.yaml +4 -0
  121. package/.local/skills/swiftui-view-refactor/references/mv-patterns.md +161 -0
  122. package/bundled/manifest.json +1 -1
  123. package/package.json +1 -1
@@ -0,0 +1,162 @@
1
+ ---
2
+ name: swiftui-expert-skill
3
+ description: Use when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state management, view composition, performance, Liquid Glass adoption, or Instruments `.trace` capture/analysis for hangs, hitches, CPU hotspots, or
4
+ excessive view updates.
5
+ ---
6
+
7
+ # SwiftUI Expert Skill
8
+
9
+ ## Operating Rules
10
+
11
+ - Consult `references/latest-apis.md` at the start of every task to avoid deprecated APIs
12
+ - Prefer native SwiftUI APIs over UIKit/AppKit bridging unless bridging is necessary
13
+ - Focus on correctness and performance; do not enforce specific architectures (MVVM, VIPER, etc.)
14
+ - Encourage separating business logic from views for testability without mandating how
15
+ - Follow Apple's Human Interface Guidelines and API design patterns
16
+ - Only adopt Liquid Glass when explicitly requested by the user (see `references/liquid-glass.md`)
17
+ - Present performance optimizations as suggestions, not requirements
18
+ - Use `#available` gating with sensible fallbacks for version-specific APIs
19
+
20
+ ## Task Workflow
21
+
22
+ ### Review existing SwiftUI code
23
+ - Read the code under review and identify which topics apply
24
+ - Flag deprecated APIs (compare against `references/latest-apis.md`)
25
+ - Run the Topic Router below for each relevant topic
26
+ - Validate `#available` gating and fallback paths for iOS 26+ features
27
+
28
+ ### Improve existing SwiftUI code
29
+ - Audit current implementation against the Topic Router topics
30
+ - Replace deprecated APIs with modern equivalents from `references/latest-apis.md`
31
+ - Refactor hot paths to reduce unnecessary state updates
32
+ - Extract complex view bodies into separate subviews
33
+ - Suggest image downsampling when `UIImage(data:)` is encountered (optional optimization, see `references/image-optimization.md`)
34
+
35
+ ### Implement new SwiftUI feature
36
+ - Design data flow first: identify owned vs injected state
37
+ - Structure views for optimal diffing (extract subviews early)
38
+ - Apply correct animation patterns (implicit vs explicit, transitions)
39
+ - Use `Button` for all tappable elements; add accessibility grouping and labels
40
+ - Gate version-specific APIs with `#available` and provide fallbacks
41
+
42
+ ### Record a new Instruments trace
43
+ Trigger when the user asks to "record a trace", "profile the app", "capture a session", etc. Full reference: `references/trace-recording.md`.
44
+
45
+ 1. **Confirm target** — attach to a running app, launch an app, or record all processes? If the user didn't say, ask. List connected devices when useful:
46
+ ```bash
47
+ python3 "${SKILL_DIR}/scripts/record_trace.py" --list-devices
48
+ ```
49
+ 2. **Pick a template based on target kind** — the `SwiftUI` template populates the SwiftUI lane on any **real device**: a physical iOS/iPadOS device **or the host Mac**. The only exception is the **iOS Simulator**, where the SwiftUI lane comes back empty — switch to `--template "Time Profiler"` in that case (still gives Time Profiler + Hangs + Animation Hitches). Always check `--list-devices`: `simulators` kind → `Time Profiler`; `devices` kind (real devices and the host Mac) → default `SwiftUI`. Full decision table in `references/trace-recording.md`.
50
+ 3. **Start the recording**. For agent-driven sessions where the user says "I'll tell you when I'm done", start in the background and use a stop-file:
51
+ ```bash
52
+ python3 "${SKILL_DIR}/scripts/record_trace.py" \
53
+ --device "<name|udid>" --attach "<AppName>" \
54
+ --stop-file /tmp/stop-trace --output ~/Desktop/session.trace
55
+ ```
56
+ For interactive sessions, just tell the user to press Ctrl+C when done.
57
+ 4. **Signal stop** — when the user says they've finished exercising the app, `touch /tmp/stop-trace`. The script cleanly SIGINTs xctrace and waits up to 60s for finalisation.
58
+ 5. **Analyse** the resulting trace (flow into the "Trace-driven improvement" workflow below).
59
+
60
+ ### Trace-driven improvement (Instruments `.trace` provided)
61
+ Trigger whenever the user's request references a `.trace` file. A target SwiftUI source file is **optional** — if given, cite specific lines; if not, recommend where to look based on view names and symbols the trace already reveals.
62
+
63
+ Full reference: `references/trace-analysis.md`. Summary of the composition pattern:
64
+
65
+ 1. **Scope the analysis.** Ask yourself: does the user want the whole trace, or a slice?
66
+ - "focus on X / after X / between X and Y / during X" → **resolve to a window first** (see step 2).
67
+ - No scoping cue → analyse the whole trace.
68
+ 2. **Resolve a window (only if the user scoped).** The parser exposes two discovery modes:
69
+ ```bash
70
+ # Find a log that marks the start/end of the region of interest:
71
+ python3 "${SKILL_DIR}/scripts/analyze_trace.py" --trace <path> \
72
+ --list-logs --log-message-contains "loaded feed" --log-limit 5
73
+ # Or list os_signpost intervals (paired begin/end), filterable by name:
74
+ python3 "${SKILL_DIR}/scripts/analyze_trace.py" --trace <path> \
75
+ --list-signposts --signpost-name-contains "ImageDecode"
76
+ ```
77
+ Both modes accept `--window START_MS:END_MS` to scope discovery. Pick the `time_ms` (for logs) or `start_ms`/`end_ms` (for signposts) that match the user's description. Build a window like `--window 10400:11700`.
78
+ 3. **Run the main analysis** (with or without `--window`):
79
+ ```bash
80
+ python3 "${SKILL_DIR}/scripts/analyze_trace.py" --trace <path> \
81
+ --json-only --top 10 [--window START_MS:END_MS]
82
+ ```
83
+ 4. **Interpret with `references/trace-analysis.md`** — key diagnostics:
84
+ - `main_running_coverage_pct` inside each correlation (<25% = blocked; ≥75% = CPU-bound).
85
+ - `swiftui-causes.top_sources` reveals *why* updates keep happening — high-edge-count sources like `UserDefaultObserver.send()` or wide `EnvironmentWriter` entries are structural invalidation bugs. Fixing one often collapses many downstream hot views.
86
+ 5. **When a specific view shows as expensive, ask who's invalidating it.** Use `--fanin-for "<view name>"` to get the ranked list of source nodes driving the updates.
87
+ 6. **Optionally ground in source.** If the user pointed at a file, read it and match view names / user-code symbols against identifiers there. If not, recommend which files to open based on the view names SwiftUI reported.
88
+ 7. **Return a prioritised plan.** Cite evidence (coverage %, hot symbol, overlapping view, log timestamp, cause-graph edges) and route each recommendation to a Topic Router reference.
89
+ 8. Only edit code if the user asked for edits.
90
+
91
+ ### Topic Router
92
+
93
+ Consult the reference file for each topic relevant to the current task:
94
+
95
+ | Topic | Reference |
96
+ |-------|-----------|
97
+ | State management | `references/state-management.md` |
98
+ | View composition | `references/view-structure.md` |
99
+ | Performance | `references/performance-patterns.md` |
100
+ | Lists and ForEach | `references/list-patterns.md` |
101
+ | Layout | `references/layout-best-practices.md` |
102
+ | Sheets and navigation | `references/sheet-navigation-patterns.md` |
103
+ | ScrollView | `references/scroll-patterns.md` |
104
+ | Focus management | `references/focus-patterns.md` |
105
+ | Animations (basics) | `references/animation-basics.md` |
106
+ | Animations (transitions) | `references/animation-transitions.md` |
107
+ | Animations (advanced) | `references/animation-advanced.md` |
108
+ | Accessibility | `references/accessibility-patterns.md` |
109
+ | Swift Charts | `references/charts.md` |
110
+ | Charts accessibility | `references/charts-accessibility.md` |
111
+ | Image optimization | `references/image-optimization.md` |
112
+ | Liquid Glass (iOS 26+) | `references/liquid-glass.md` |
113
+ | macOS scenes | `references/macos-scenes.md` |
114
+ | macOS window styling | `references/macos-window-styling.md` |
115
+ | macOS views | `references/macos-views.md` |
116
+ | Text patterns | `references/text-patterns.md` |
117
+ | Deprecated API lookup | `references/latest-apis.md` |
118
+ | Instruments trace analysis | `references/trace-analysis.md` |
119
+ | Instruments trace recording | `references/trace-recording.md` |
120
+
121
+ ## Correctness Checklist
122
+
123
+ These are hard rules -- violations are always bugs:
124
+
125
+ - [ ] `@State` properties are `private`
126
+ - [ ] `@Binding` only where a child modifies parent state
127
+ - [ ] Passed values never declared as `@State` or `@StateObject` (they ignore updates)
128
+ - [ ] `@StateObject` for view-owned objects; `@ObservedObject` for injected
129
+ - [ ] iOS 17+: `@State` with `@Observable`; `@Bindable` for injected observables needing bindings
130
+ - [ ] `ForEach` uses stable identity (never `.indices` for dynamic content)
131
+ - [ ] Constant number of views per `ForEach` element
132
+ - [ ] `.animation(_:value:)` always includes the `value` parameter
133
+ - [ ] `@FocusState` properties are `private`
134
+ - [ ] No redundant `@FocusState` writes inside tap gesture handlers on `.focusable()` views
135
+ - [ ] iOS 26+ APIs gated with `#available` and fallback provided
136
+ - [ ] `import Charts` present in files using chart types
137
+
138
+ ## References
139
+
140
+ - `references/latest-apis.md` -- **Read first for every task.** Deprecated-to-modern API transitions (iOS 15+ through iOS 26+)
141
+ - `references/state-management.md` -- Property wrappers, data flow, `@Observable` migration
142
+ - `references/view-structure.md` -- View extraction, container patterns, `@ViewBuilder`
143
+ - `references/performance-patterns.md` -- Hot-path optimization, update control, `_logChanges()`
144
+ - `references/list-patterns.md` -- ForEach identity, Table (iOS 16+), inline filtering pitfalls
145
+ - `references/layout-best-practices.md` -- Layout patterns, GeometryReader alternatives
146
+ - `references/accessibility-patterns.md` -- VoiceOver, Dynamic Type, grouping, traits
147
+ - `references/animation-basics.md` -- Implicit/explicit animations, timing, performance
148
+ - `references/animation-transitions.md` -- View transitions, `matchedGeometryEffect`, `Animatable`
149
+ - `references/animation-advanced.md` -- Phase/keyframe animations (iOS 17+), `@Animatable` macro (iOS 26+)
150
+ - `references/charts.md` -- Swift Charts marks, axes, selection, styling, Chart3D (iOS 26+)
151
+ - `references/charts-accessibility.md` -- Charts VoiceOver, Audio Graph, fallback strategies
152
+ - `references/sheet-navigation-patterns.md` -- Sheets, NavigationSplitView, Inspector
153
+ - `references/scroll-patterns.md` -- ScrollViewReader, programmatic scrolling
154
+ - `references/focus-patterns.md` -- Focus state, focusable views, focused values, default focus, common pitfalls
155
+ - `references/image-optimization.md` -- AsyncImage, downsampling, caching
156
+ - `references/liquid-glass.md` -- iOS 26+ Liquid Glass effects and fallback patterns
157
+ - `references/macos-scenes.md` -- Settings, MenuBarExtra, WindowGroup, multi-window
158
+ - `references/macos-window-styling.md` -- Toolbar styles, window sizing, Commands
159
+ - `references/macos-views.md` -- HSplitView, Table, PasteButton, AppKit interop
160
+ - `references/text-patterns.md` -- Text initializer selection, verbatim vs localized
161
+ - `references/trace-analysis.md` -- Parse Instruments `.trace` files via `scripts/analyze_trace.py`; interpret main-thread coverage, high-severity SwiftUI updates, hitch narratives, and map findings back to source files
162
+ - `references/trace-recording.md` -- Record a new trace via `scripts/record_trace.py`: attach to a running app, launch one fresh, or capture a manually-stopped session; supports stop-file for agent-driven flows
@@ -0,0 +1,215 @@
1
+ # SwiftUI Accessibility Patterns Reference
2
+
3
+ ## Table of Contents
4
+
5
+ - [Core Principle](#core-principle)
6
+ - [Dynamic Type and @ScaledMetric](#dynamic-type-and-scaledmetric)
7
+ - [Accessibility Traits](#accessibility-traits)
8
+ - [Decorative Images](#decorative-images)
9
+ - [Element Grouping](#element-grouping)
10
+ - [Custom Controls](#custom-controls)
11
+ - [Summary Checklist](#summary-checklist)
12
+
13
+ ## Core Principle
14
+
15
+ Prefer `Button` over `onTapGesture` for tappable elements. `Button` provides VoiceOver support, focus handling, and proper traits for free.
16
+
17
+ ## Dynamic Type and @ScaledMetric
18
+
19
+ System text styles scale with Dynamic Type automatically. Prefer built-in styles like `.largeTitle`, `.title`, `.title2`, `.title3`, `.headline`, `.subheadline`, `.body`, `.callout`, `.footnote`, `.caption`, and `.caption2` when they fit your UI:
20
+
21
+ ```swift
22
+ VStack(alignment: .leading) {
23
+ Text("Inbox")
24
+ .font(.title2)
25
+ Text("3 unread messages")
26
+ .font(.body)
27
+ Text("Updated just now")
28
+ .font(.caption)
29
+ }
30
+ ```
31
+
32
+ For custom fonts, use a Dynamic Type-aware font initializer so the text still follows the user's preferred content size:
33
+
34
+ ```swift
35
+ VStack(alignment: .leading) {
36
+ Text("Article")
37
+ .font(.custom("SourceSerif4-Semibold", size: 28, relativeTo: .title2))
38
+ Text("Body copy")
39
+ .font(.custom("SourceSerif4-Regular", size: 17))
40
+ }
41
+ ```
42
+
43
+ `Font.custom(_:size:relativeTo:)` lets you match a specific text style. `Font.custom(_:size:)` scales relative to the body style. Avoid fixed-size custom fonts for primary content that should respond to Dynamic Type.
44
+
45
+ For non-text numeric values like padding, spacing, and image sizes, use `@ScaledMetric`:
46
+
47
+ ```swift
48
+ struct ProfileHeader: View {
49
+ @ScaledMetric private var avatarSize = 60.0
50
+ @ScaledMetric private var spacing = 12.0
51
+
52
+ var body: some View {
53
+ HStack(spacing: spacing) {
54
+ Image("avatar")
55
+ .resizable()
56
+ .frame(width: avatarSize, height: avatarSize)
57
+ Text("Username")
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ Specify a `relativeTo` text style when the value should track a specific Dynamic Type style, including for images or icons that should stay proportional to nearby text:
64
+
65
+ ```swift
66
+ struct StatusRow: View {
67
+ @ScaledMetric(relativeTo: .body) private var iconSize = 18.0
68
+
69
+ var body: some View {
70
+ HStack(spacing: 8) {
71
+ Image(systemName: "checkmark.circle.fill")
72
+ .font(.system(size: iconSize))
73
+ Text("Synced")
74
+ .font(.custom("AvenirNext-Regular", size: 17, relativeTo: .body))
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Accessibility Traits
81
+
82
+ Use `accessibilityAddTraits` and `accessibilityRemoveTraits` for state-driven traits:
83
+
84
+ ```swift
85
+ Text(item.title)
86
+ .accessibilityAddTraits(item.isSelected ? [.isSelected, .isButton] : .isButton)
87
+ ```
88
+
89
+ Use `.disabled(true)` to make VoiceOver announce "Dimmed" for non-interactive elements.
90
+
91
+ ## Decorative Images
92
+
93
+ Use `Image(decorative:bundle:)` when an asset image is purely visual and should not appear in the accessibility tree.
94
+
95
+ ```swift
96
+ Image(decorative: "confetti")
97
+ ```
98
+
99
+ This is appropriate for backgrounds, flourishes, and icons that do not add meaning beyond nearby text.
100
+
101
+ If the image conveys information, keep it accessible and provide a clear label:
102
+
103
+ ```swift
104
+ Image("receipt")
105
+ .accessibilityLabel("Receipt")
106
+ ```
107
+
108
+ For non-asset images, such as SF Symbols, hide decorative content with `accessibilityHidden(true)` instead:
109
+
110
+ ```swift
111
+ Image(systemName: "sparkles")
112
+ .accessibilityHidden(true)
113
+ ```
114
+
115
+ ## Element Grouping
116
+
117
+ ### .combine -- Auto-join child labels
118
+
119
+ ```swift
120
+ HStack {
121
+ Image(systemName: "star.fill")
122
+ Text("Favorites")
123
+ Text("(\(count))")
124
+ }
125
+ .accessibilityElement(children: .combine)
126
+ ```
127
+
128
+ VoiceOver reads all child labels as one element, separated by commas.
129
+
130
+ ### .ignore -- Manual label for container
131
+
132
+ ```swift
133
+ HStack {
134
+ Text(item.name)
135
+ Spacer()
136
+ Text(item.price)
137
+ }
138
+ .accessibilityElement(children: .ignore)
139
+ .accessibilityLabel("\(item.name), \(item.price)")
140
+ ```
141
+
142
+ ### .contain -- Semantic grouping
143
+
144
+ ```swift
145
+ HStack {
146
+ ForEach(tabs) { tab in
147
+ TabButton(tab: tab)
148
+ }
149
+ }
150
+ .accessibilityElement(children: .contain)
151
+ .accessibilityLabel("Tab bar")
152
+ ```
153
+
154
+ VoiceOver announces the container name when focus enters/exits.
155
+
156
+ ## Custom Controls
157
+
158
+ ### Adjustable controls (increment/decrement)
159
+
160
+ ```swift
161
+ PageControl(selectedIndex: $selectedIndex, pageCount: pageCount)
162
+ .accessibilityElement()
163
+ .accessibilityValue("Page \(selectedIndex + 1) of \(pageCount)")
164
+ .accessibilityAdjustableAction { direction in
165
+ switch direction {
166
+ case .increment:
167
+ guard selectedIndex < pageCount - 1 else { break }
168
+ selectedIndex += 1
169
+ case .decrement:
170
+ guard selectedIndex > 0 else { break }
171
+ selectedIndex -= 1
172
+ @unknown default:
173
+ break
174
+ }
175
+ }
176
+ ```
177
+
178
+ ### Representing custom views as native controls
179
+
180
+ When a custom view should behave like a native control for accessibility:
181
+
182
+ ```swift
183
+ HStack {
184
+ Text(label)
185
+ Toggle("", isOn: $isOn)
186
+ }
187
+ .accessibilityRepresentation {
188
+ Toggle(label, isOn: $isOn)
189
+ }
190
+ ```
191
+
192
+ ### Label-content pairing
193
+
194
+ ```swift
195
+ @Namespace private var ns
196
+
197
+ HStack {
198
+ Text("Volume")
199
+ .accessibilityLabeledPair(role: .label, id: "volume", in: ns)
200
+ Slider(value: $volume)
201
+ .accessibilityLabeledPair(role: .content, id: "volume", in: ns)
202
+ }
203
+ ```
204
+
205
+ ## Summary Checklist
206
+
207
+ - [ ] Use `Button` instead of `onTapGesture` for tappable elements
208
+ - [ ] Use built-in text styles or Dynamic Type-aware custom fonts for text
209
+ - [ ] Use `@ScaledMetric` for custom values that should scale with Dynamic Type
210
+ - [ ] Mark purely decorative images as decorative or hidden from accessibility
211
+ - [ ] Group related elements with `accessibilityElement(children:)`
212
+ - [ ] Provide `accessibilityLabel` when default labels are unclear
213
+ - [ ] Use `accessibilityRepresentation` for custom controls
214
+ - [ ] Use `accessibilityAdjustableAction` for increment/decrement controls
215
+ - [ ] Ensure navigation flow is logical when using VoiceOver grouping