swiftui-pro
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReview 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:
- Check for deprecated API using .
references/api.md - Check that views, modifiers, and animations have been written optimally using .
references/views.md - Validate that data flow is configured correctly using .
references/data.md - Ensure navigation is updated and performant using .
references/navigation.md - Ensure the code uses designs that are accessible and compliant with Apple’s Human Interface Guidelines using .
references/design.md - Validate accessibility compliance including Dynamic Type, VoiceOver, and Reduce Motion using .
references/accessibility.md - Ensure the code is able to run efficiently using .
references/performance.md - Quick validation of Swift code using .
references/swift.md - Final code hygiene check using .
references/hygiene.md
If doing a partial review, load only the relevant reference files.
审查Swift和SwiftUI代码的正确性、现代API使用情况以及是否符合项目规范。仅报告真实存在的问题——不要吹毛求疵或编造问题。
审查流程:
- 使用检查是否存在已弃用的API。
references/api.md - 使用检查视图、修饰符和动画是否经过优化编写。
references/views.md - 使用验证数据流配置是否正确。
references/data.md - 使用确保导航已更新且性能良好。
references/navigation.md - 使用确保代码采用的设计符合苹果人机界面指南且具备可访问性。
references/design.md - 使用验证可访问性合规性,包括动态类型、VoiceOver和减少运动效果。
references/accessibility.md - 使用确保代码能够高效运行。
references/performance.md - 使用快速验证Swift代码。
references/swift.md - 使用进行最终代码整洁度检查。
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:
- State the file and relevant line(s).
- Name the rule being violated (e.g., "Use instead of
foregroundStyle()").foregroundColor() - 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:
按文件整理检查结果。对于每个问题:
- 说明文件和相关行号。
- 指出违反的规则(例如:“使用替代
foregroundStyle()”)。foregroundColor() - 展示简短的修复前后代码对比。
跳过没有问题的文件。最后给出按优先级排序的最具影响的修改总结。
示例输出:
ContentView.swift
ContentView.swift
Line 12: Use instead of .
foregroundStyle()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 in view body - use with instead.
Binding(get:set:)@StateonChange()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:)@StateonChange()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
总结
- Accessibility (high): The add button on line 24 is invisible to VoiceOver.
- Deprecated API (medium): on line 12 should be
foregroundColor().foregroundStyle() - Data flow (medium): The manual binding on line 31 is fragile and harder to maintain.
End of example.
- 可访问性(高优先级): 第24行的添加按钮对VoiceOver不可见。
- 已弃用API(中优先级): 第12行的应替换为
foregroundColor()。foregroundStyle() - 数据流(中优先级): 第31行的手动绑定易出错且难以维护。
示例结束。
References
参考文件
- - Dynamic Type, VoiceOver, Reduce Motion, and other accessibility requirements.
references/accessibility.md - - updating code for modern API, and the deprecated code it replaces.
references/api.md - - guidance for building accessible apps that meet Apple’s Human Interface Guidelines.
references/design.md - - making code compile cleanly and be maintainable in the long term.
references/hygiene.md - - navigation using
references/navigation.md/NavigationStack, plus alerts, confirmation dialogs, and sheets.NavigationSplitView - - optimizing SwiftUI code for maximum performance.
references/performance.md - - data flow, shared state, and property wrappers.
references/data.md - - tips on writing modern Swift code, including using Swift Concurrency effectively.
references/swift.md - - view structure, composition, and animation.
references/views.md
- - 动态类型、VoiceOver、减少运动效果及其他可访问性要求。
references/accessibility.md - - 代码的现代API更新指南及被替代的已弃用代码。
references/api.md - - 构建符合苹果人机界面指南的可访问应用的指导。
references/design.md - - 确保代码编译整洁并具备长期可维护性的指南。
references/hygiene.md - - 使用
references/navigation.md/NavigationStack进行导航,以及提醒框、确认对话框和表单的相关内容。NavigationSplitView - - 优化SwiftUI代码以实现最佳性能的指南。
references/performance.md - - 数据流、共享状态及属性包装器的相关内容。
references/data.md - - 编写现代Swift代码的技巧,包括有效使用Swift并发机制。
references/swift.md - - 视图结构、组合及动画的相关内容。
references/views.md