SwiftUI Code Review
Quick Reference
references/state-management.md |
| LazyStacks, AnyView, ForEach, identity |
references/performance.md |
| VoiceOver, Dynamic Type, labels, traits |
references/accessibility.md |
Review Checklist
- - [ ] View body under 10 composed elements (extract subviews)
- [ ] Modifiers in correct order (padding before background)
- [ ] @StateObject for view-owned objects, @ObservedObject for passed objects
- [ ] @Bindable used for two-way bindings to @Observable (iOS 17+)
- [ ] LazyVStack/LazyHStack for scrolling lists with 50+ items
- [ ] No AnyView (use @ViewBuilder or generics instead)
- [ ] ForEach uses stable Identifiable IDs (not array indices)
- [ ] All images/icons have accessibilityLabel
- [ ] Custom controls have accessibilityAddTraits(.isButton)
- [ ] Dynamic Type supported (no fixed font sizes)
- [ ] .task modifier for async work (not onAppear + Task)
When to Load References
- - Complex view bodies or modifier chains -> view-composition.md
- Property wrapper usage (@State, @Observable) -> state-management.md
- List performance or view identity issues -> performance.md
- VoiceOver or accessibility implementation -> accessibility.md
Review Questions
- 1. Could this large view body be split into smaller, reusable Views?
- Is modifier order intentional? (padding -> background -> frame)
- Is @StateObject/@ObservedObject usage correct for ownership?
- Could LazyVStack improve this ScrollView's performance?
- Would VoiceOver users understand this interface?
SwiftUI 代码审查
快速参考
references/state-management.md |
| LazyStacks、AnyView、ForEach、标识符 |
references/performance.md |
| VoiceOver、动态字体、标签、特征 |
references/accessibility.md |
审查清单
- - [ ] View body 不超过10个组合元素(提取子视图)
- [ ] 修饰符顺序正确(padding 在 background 之前)
- [ ] @StateObject 用于视图拥有的对象,@ObservedObject 用于传入的对象
- [ ] @Bindable 用于与 @Observable 的双向绑定(iOS 17+)
- [ ] 50+ 项的滚动列表使用 LazyVStack/LazyHStack
- [ ] 不使用 AnyView(改用 @ViewBuilder 或泛型)
- [ ] ForEach 使用稳定的 Identifiable ID(而非数组索引)
- [ ] 所有图片/图标都有 accessibilityLabel
- [ ] 自定义控件有 accessibilityAddTraits(.isButton)
- [ ] 支持动态字体(不使用固定字号)
- [ ] 异步工作使用 .task 修饰符(而非 onAppear + Task)
何时加载参考文档
- - 复杂视图 body 或修饰符链 -> view-composition.md
- 属性包装器用法(@State、@Observable)-> state-management.md
- 列表性能或视图标识问题 -> performance.md
- VoiceOver 或无障碍实现 -> accessibility.md
审查问题
- 1. 这个大型视图 body 能否拆分为更小、可复用的视图?
- 修饰符顺序是否有意为之?(padding -> background -> frame)
- @StateObject/@ObservedObject 的所有权使用是否正确?
- LazyVStack 能否提升此 ScrollView 的性能?
- VoiceOver 用户能否理解此界面?