swiftui-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SwiftUI Code Review

SwiftUI代码审查

Quick Reference

快速参考

Issue TypeReference
View extraction, modifiers, body complexityreferences/view-composition.md
@State, @Binding, @Observable, @Bindablereferences/state-management.md
LazyStacks, AnyView, ForEach, identityreferences/performance.md
VoiceOver, Dynamic Type, labels, traitsreferences/accessibility.md
问题类型参考文档
视图提取、修饰符、body复杂度references/view-composition.md
@State、@Binding、@Observable、@Bindablereferences/state-management.md
LazyStacks、AnyView、ForEach、标识references/performance.md
VoiceOver、动态类型、标签、特性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)
  • 视图body包含的组合元素不超过10个(提取子视图)
  • 修饰符顺序正确(padding在background之前)
  • 视图自有对象使用@StateObject,传入对象使用@ObservedObject
  • 对@Observable的双向绑定使用@Bindable(iOS 17+)
  • 包含50+条目的滚动列表使用LazyVStack/LazyHStack
  • 不使用AnyView(改用@ViewBuilder或泛型)
  • ForEach使用稳定的Identifiable ID(而非数组索引)
  • 所有图片/图标都有accessibilityLabel
  • 自定义控件添加accessibilityAddTraits(.isButton)
  • 支持动态类型(无固定字体大小)
  • 使用.task修饰符处理异步工作(而非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
  • 复杂视图body或修饰符链 -> view-composition.md
  • 属性包装器使用(@State、@Observable)-> state-management.md
  • 列表性能或视图标识问题 -> performance.md
  • VoiceOver或可访问性实现 -> accessibility.md

Review Questions

审查问题

  1. Could this large view body be split into smaller, reusable Views?
  2. Is modifier order intentional? (padding -> background -> frame)
  3. Is @StateObject/@ObservedObject usage correct for ownership?
  4. Could LazyVStack improve this ScrollView's performance?
  5. Would VoiceOver users understand this interface?
  1. 这个大型视图body能否拆分为更小的可重用Views?
  2. 修饰符顺序是否符合预期?(padding -> background -> frame)
  3. @StateObject/@ObservedObject的使用是否符合所有权规则?
  4. LazyVStack能否提升这个ScrollView的性能?
  5. VoiceOver用户能否理解这个界面?