swiftui-standards
Use when building or reviewing SwiftUI UI in a touchstone repo — declarative views, the Observation framework for state, navigation, in-view concurrency, identity/perf, and the a11y/test surface. Triggers on SwiftUI views, `.swift` files declaring `: View`/`some View`, `@Observable`, `@State`/`@Bindable`, `NavigationStack`, `#Preview`. Boundary: Swift-language rules (concurrency, optionals, value types, packages) → swift skill; this layers on top.
- License 许可
- MIT
- 最近更新
- 2026-08-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- swiftui-standards
- license
- MIT
- metadata
- { "author": "touchstone", "version": "0.2.0" }
- description
- Use when building or reviewing SwiftUI UI in a touchstone repo — declarative views, the Observation framework for state, navigation, in-view concurrency, identity/perf, and the a11y/test surface. Triggers on SwiftUI views, `.swift` files declaring `: View`/`some View`, `@Observable`, `@State`/`@Bindable`, `NavigationStack`, `#Preview`. Boundary: Swift-language rules (concurrency, optionals, value types, packages) → swift skill; this layers on top.
03 SKILL.md 正文
SwiftUI (framework)
Full standard: standards/frameworks/swiftui.md (layers on standards/languages/swift.md).
This skill inlines the load-bearing rules so it stays useful when installed standalone in
~/.claude/skills/:
Always
- Observation framework, iOS 17+ — mark reference models
@Observable; own them in@State, inject via@Environment, get$-bindings with@Bindable. NoObservableObject/@Published/@StateObjectin new code. - One source of truth per state; data flows down, events up — derive values, never duplicate
state into a second
@Stateyou hand-sync. - Small composed views — extract a subview (own rebuild scope) over a
-> some Viewhelper; no reflexiveAnyView. - Plain SwiftUI (MV) by default — logic on
@MainActor@Observablemodels, not inbody; reach for a per-screen view-model only for genuinely complex state (scale-up). NavigationStack+ value-driven/type-safe path (neverNavigationView); program nav by mutating the path..task/.task(id:)for async (auto-cancels) — neveronAppear { Task {} }; bound every external await with a timeout.
Don't get burned
@Stateseeded from a parent prop won't update — pass a@Bindingor the value instead.- Wrong
ForEachidentity recycles state into the wrong row — key on a stable domain ID, never the array index when rows move. AnyViewand helper methods erase identity / always rebuild — they quietly kill diffing and perf.- Bridge to UIKit (
UIViewRepresentable) only when SwiftUI lacks the API — check for a native one first (PhotosPicker,Map,ShareLink); keepupdateUIViewside-effect-free. - Migration is mechanical —
@StateObject→@State,@ObservedObject→let/@Bindable,@EnvironmentObject→@Environment(Model.self), delete every@Published; do it model-by-model.
Done
Observation state (no ObservableObject) · small composed views, stable identity · MV logic off
body · NavigationStack typed path · .task async, awaits bounded · lazy containers, pure body ·
#Previews cover empty/loading/error + dark + Dynamic Type · a11y labels/traits + VoiceOver ·
Swift Testing for logic, XCUITest by accessibility id. See standards/frameworks/swiftui.md.
04 同仓库更多 Skills
ok-standards
Use when writing shell, per standards/languages/shell.md.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.