swiftui-pro

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Review Swift and SwiftUI code for correctness, modern API usage, and adherence to project conventions. Report only genuine problems - do not nitpick or invent issues.
Review process:
  1. Check for deprecated API using
    references/api.md
    .
  2. Check that views, modifiers, and animations have been written optimally using
    references/views.md
    .
  3. Validate that data flow is configured correctly using
    references/data.md
    .
  4. Ensure navigation is updated and performant using
    references/navigation.md
    .
  5. Ensure the code uses designs that are accessible and compliant with Apple’s Human Interface Guidelines using
    references/design.md
    .
  6. Validate accessibility compliance including Dynamic Type, VoiceOver, and Reduce Motion using
    references/accessibility.md
    .
  7. Ensure the code is able to run efficiently using
    references/performance.md
    .
  8. Quick validation of Swift code using
    references/swift.md
    .
  9. Final code hygiene check using
    references/hygiene.md
    .
If doing a partial review, load only the relevant reference files.
审查Swift和SwiftUI代码的正确性、现代API使用情况以及是否符合项目规范。仅报告真实存在的问题——不要吹毛求疵或编造问题。
审查流程:
  1. 使用
    references/api.md
    检查是否存在已弃用的API。
  2. 使用
    references/views.md
    检查视图、修饰符和动画是否经过优化编写。
  3. 使用
    references/data.md
    验证数据流配置是否正确。
  4. 使用
    references/navigation.md
    确保导航已更新且性能良好。
  5. 使用
    references/design.md
    确保代码采用的设计符合苹果人机界面指南且具备可访问性。
  6. 使用
    references/accessibility.md
    验证可访问性合规性,包括动态类型、VoiceOver和减少运动效果。
  7. 使用
    references/performance.md
    确保代码能够高效运行。
  8. 使用
    references/swift.md
    快速验证Swift代码。
  9. 使用
    references/hygiene.md
    进行最终代码整洁度检查。
如果进行部分审查,仅加载相关的参考文件。

Core Instructions

核心说明

  • iOS 26 exists, and is the default deployment target for new apps.
  • Target Swift 6.2 or later, using modern Swift concurrency.
  • As a SwiftUI developer, the user will want to avoid UIKit unless requested.
  • Do not introduce third-party frameworks without asking first.
  • Break different types up into different Swift files rather than placing multiple structs, classes, or enums into a single file.
  • Use a consistent project structure, with folder layout determined by app features.
  • iOS 26已发布,是新应用的默认部署目标。
  • 目标使用Swift 6.2或更高版本,采用现代Swift并发机制。
  • 作为SwiftUI开发者,除非有要求,否则应避免使用UIKit。
  • 未经询问,不要引入第三方框架。
  • 将不同类型拆分到不同的Swift文件中,不要将多个结构体、类或枚举放在单个文件内。
  • 使用一致的项目结构,文件夹布局根据应用功能确定。

Output Format

输出格式

Organize findings by file. For each issue:
  1. State the file and relevant line(s).
  2. Name the rule being violated (e.g., "Use
    foregroundStyle()
    instead of
    foregroundColor()
    ").
  3. Show a brief before/after code fix.
Skip files with no issues. End with a prioritized summary of the most impactful changes to make first.
Example output:
按文件整理检查结果。对于每个问题:
  1. 说明文件和相关行号。
  2. 指出违反的规则(例如:“使用
    foregroundStyle()
    替代
    foregroundColor()
    ”)。
  3. 展示简短的修复前后代码对比。
跳过没有问题的文件。最后给出按优先级排序的最具影响的修改总结。
示例输出:

ContentView.swift

ContentView.swift

Line 12: Use
foregroundStyle()
instead of
foregroundColor()
.
swift
// Before
Text("Hello").foregroundColor(.red)

// After
Text("Hello").foregroundStyle(.red)
Line 24: Icon-only button is bad for VoiceOver - add a text label.
swift
// Before
Button(action: addUser) {
    Image(systemName: "plus")
}

// After
Button("Add User", systemImage: "plus", action: addUser)
Line 31: Avoid
Binding(get:set:)
in view body - use
@State
with
onChange()
instead.
swift
// Before
TextField("Username", text: Binding(
    get: { model.username },
    set: { model.username = $0; model.save() }
))

// After
TextField("Username", text: $model.username)
    .onChange(of: model.username) {
        model.save()
    }
第12行:使用
foregroundStyle()
替代
foregroundColor()
swift
// Before
Text("Hello").foregroundColor(.red)

// After
Text("Hello").foregroundStyle(.red)
第24行:仅含图标按钮对VoiceOver不友好 - 添加文本标签。
swift
// Before
Button(action: addUser) {
    Image(systemName: "plus")
}

// After
Button("Add User", systemImage: "plus", action: addUser)
第31行:避免在视图体中使用
Binding(get:set:)
- 改用
@State
配合
onChange()
swift
// Before
TextField("Username", text: Binding(
    get: { model.username },
    set: { model.username = $0; model.save() }
))

// After
TextField("Username", text: $model.username)
    .onChange(of: model.username) {
        model.save()
    }

Summary

总结

  1. Accessibility (high): The add button on line 24 is invisible to VoiceOver.
  2. Deprecated API (medium):
    foregroundColor()
    on line 12 should be
    foregroundStyle()
    .
  3. Data flow (medium): The manual binding on line 31 is fragile and harder to maintain.
End of example.
  1. 可访问性(高优先级): 第24行的添加按钮对VoiceOver不可见。
  2. 已弃用API(中优先级): 第12行的
    foregroundColor()
    应替换为
    foregroundStyle()
  3. 数据流(中优先级): 第31行的手动绑定易出错且难以维护。
示例结束。

References

参考文件

  • references/accessibility.md
    - Dynamic Type, VoiceOver, Reduce Motion, and other accessibility requirements.
  • references/api.md
    - updating code for modern API, and the deprecated code it replaces.
  • references/design.md
    - guidance for building accessible apps that meet Apple’s Human Interface Guidelines.
  • references/hygiene.md
    - making code compile cleanly and be maintainable in the long term.
  • references/navigation.md
    - navigation using
    NavigationStack
    /
    NavigationSplitView
    , plus alerts, confirmation dialogs, and sheets.
  • references/performance.md
    - optimizing SwiftUI code for maximum performance.
  • references/data.md
    - data flow, shared state, and property wrappers.
  • references/swift.md
    - tips on writing modern Swift code, including using Swift Concurrency effectively.
  • references/views.md
    - view structure, composition, and animation.
  • references/accessibility.md
    - 动态类型、VoiceOver、减少运动效果及其他可访问性要求。
  • references/api.md
    - 代码的现代API更新指南及被替代的已弃用代码。
  • references/design.md
    - 构建符合苹果人机界面指南的可访问应用的指导。
  • references/hygiene.md
    - 确保代码编译整洁并具备长期可维护性的指南。
  • references/navigation.md
    - 使用
    NavigationStack
    /
    NavigationSplitView
    进行导航,以及提醒框、确认对话框和表单的相关内容。
  • references/performance.md
    - 优化SwiftUI代码以实现最佳性能的指南。
  • references/data.md
    - 数据流、共享状态及属性包装器的相关内容。
  • references/swift.md
    - 编写现代Swift代码的技巧,包括有效使用Swift并发机制。
  • references/views.md
    - 视图结构、组合及动画的相关内容。