uikit-max
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReview Swift and UIKit 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, subclassing, and composition patterns follow best practices using .
references/views.md - Validate Auto Layout usage and constraint patterns using .
references/layout.md - Ensure view controller lifecycle and architecture are correct using .
references/controllers.md - Ensure navigation patterns are modern and maintainable using .
references/navigation.md - Validate UITableView and UICollectionView usage using .
references/tableview-collectionview.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 traits using .
references/accessibility.md - Ensure the code runs efficiently using .
references/performance.md - Check concurrency and thread safety using .
references/concurrency.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和UIKit代码的正确性、现代API使用情况以及是否符合项目规范。仅报告真实存在的问题——不要吹毛求疵或捏造问题。
审查流程:
- 使用检查已弃用的API。
references/api.md - 使用检查视图、子类化和组合模式是否遵循最佳实践。
references/views.md - 使用验证Auto Layout的使用和约束模式。
references/layout.md - 使用确保视图控制器的生命周期和架构正确。
references/controllers.md - 使用确保导航模式现代化且易于维护。
references/navigation.md - 使用验证UITableView和UICollectionView的使用。
references/tableview-collectionview.md - 使用确保代码采用符合Apple人机界面指南的可访问设计。
references/design.md - 使用验证无障碍合规性,包括动态字体、VoiceOver和特性设置。
references/accessibility.md - 使用确保代码高效运行。
references/performance.md - 使用检查并发和线程安全性。
references/concurrency.md - 使用快速验证Swift代码。
references/swift.md - 使用进行最终代码整洁度检查。
references/hygiene.md
如果是部分审查,仅加载相关的参考文件。
Core Instructions
核心说明
- iOS 26 exists and is the latest iOS version. Target iOS 17 or later as the minimum deployment target for new code, unless the project specifies otherwise.
- Target Swift 6.2 or later, using modern Swift concurrency.
- Respect the project's deployment target. Before suggesting a modern API, check its availability. If the project targets an older iOS version, recommend the best available alternative and wrap newer APIs in checks. Reference files mark key APIs with their iOS version (e.g., "iOS 15+"). Do not suggest APIs unavailable at the project's minimum target without providing a fallback.
if #available - As a UIKit developer, the user expects UIKit patterns. Do not suggest SwiftUI replacements unless explicitly requested.
- Do not introduce third-party frameworks without asking first.
- Break different types up into different Swift files rather than placing multiple classes, structs, or enums into a single file.
- Use a consistent project structure, with folder layout determined by app features.
- Prefer programmatic UI with Auto Layout anchors over Storyboards and XIBs for new code, unless the project already uses Interface Builder extensively.
- iOS 26是最新版本。新项目的最低部署目标应为iOS 17或更高版本,除非项目另有规定。
- 目标Swift版本为6.2或更高,使用现代Swift并发机制。
- 尊重项目的部署目标。在建议使用现代API之前,先检查其可用性。如果项目目标是较旧的iOS版本,推荐最佳可用替代方案,并将较新的API包装在检查中。参考文件会标记关键API的iOS版本要求(例如“iOS 15+”)。在未提供回退方案的情况下,不要建议使用项目最低目标版本不支持的API。
if #available - 作为UIKit开发者,用户期望使用UIKit模式。除非明确要求,否则不要建议替换为SwiftUI。
- 未经询问,不要引入第三方框架。
- 将不同类型拆分到不同的Swift文件中,不要将多个类、结构体或枚举放在单个文件里。
- 使用一致的项目结构,根据应用功能确定文件夹布局。
- 对于新代码,优先使用带Auto Layout锚点的程序化UI,而非Storyboards和XIBs,除非项目已广泛使用Interface Builder。
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
UIAlertController").UIAlertView - 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:
按文件整理审查结果。对于每个问题:
- 说明文件和相关行号。
- 指出违反的规则(例如“使用替代
UIAlertController”)。UIAlertView - 展示简短的修复前后代码对比。
跳过无问题的文件。最后列出优先级最高的关键修改建议。
示例输出:
ProfileViewController.swift
ProfileViewController.swift
Line 8: Use instead of deprecated .
UIAlertControllerUIAlertViewswift
// Before
let alert = UIAlertView(title: "Error", message: msg, delegate: self, cancelButtonTitle: "OK")
alert.show()
// After
let alert = UIAlertController(title: "Error", message: msg, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
present(alert, animated: true)Line 24: Batch constraint activation with .
NSLayoutConstraint.activateswift
// Before
label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
label.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
// After
NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: view.topAnchor),
label.leadingAnchor.constraint(equalTo: view.leadingAnchor)
])Line 42: Set before adding constraints.
translatesAutoresizingMaskIntoConstraints = falseswift
// Before
view.addSubview(label)
label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
// After
label.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(label)
NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: view.topAnchor)
])第8行:使用替代已弃用的。
UIAlertControllerUIAlertViewswift
// Before
let alert = UIAlertView(title: "Error", message: msg, delegate: self, cancelButtonTitle: "OK")
alert.show()
// After
let alert = UIAlertController(title: "Error", message: msg, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
present(alert, animated: true)第24行:使用批量激活约束。
NSLayoutConstraint.activateswift
// Before
label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
label.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
// After
NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: view.topAnchor),
label.leadingAnchor.constraint(equalTo: view.leadingAnchor)
])第42行:添加约束前设置。
translatesAutoresizingMaskIntoConstraints = falseswift
// Before
view.addSubview(label)
label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
// After
label.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(label)
NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: view.topAnchor)
])Summary
总结
- Deprecated API (high): on line 8 must be replaced with
UIAlertView.UIAlertController - Layout (medium): Individual constraint activation on line 24 should use .
NSLayoutConstraint.activate - Layout (medium): Missing on line 42 causes constraint conflicts.
translatesAutoresizingMaskIntoConstraints
End of example.
- 已弃用API(高优先级):第8行的必须替换为
UIAlertView。UIAlertController - 布局(中优先级):第24行的单个约束激活应使用。
NSLayoutConstraint.activate - 布局(中优先级):第42行缺少会导致约束冲突。
translatesAutoresizingMaskIntoConstraints
示例结束。
References
参考资料
- — deprecated UIKit APIs and their modern replacements.
references/api.md - — UIView lifecycle, composition, subclassing, and custom drawing.
references/views.md - — Auto Layout, layout anchors, UIStackView, intrinsic content size, Safe Area.
references/layout.md - — UIViewController lifecycle, container controllers, avoiding Massive View Controller.
references/controllers.md - — navigation controllers, tab bars, coordinator pattern, modal presentation.
references/navigation.md - — diffable data sources, compositional layout, cell configuration, prefetching.
references/tableview-collectionview.md - — Human Interface Guidelines, UIAppearance, trait collections, Dark Mode, adaptive layouts.
references/design.md - — VoiceOver, Dynamic Type, accessibility traits, labels, and hints.
references/accessibility.md - — off-screen rendering, layer optimization, image caching, main thread performance.
references/performance.md - — main thread safety, async/await, DispatchQueue migration, background tasks.
references/concurrency.md - — modern Swift code, Swift concurrency, Objective-C interop.
references/swift.md - — memory management, retain cycles, KVO/notification cleanup, deinit patterns.
references/hygiene.md
- — 已弃用的UIKit API及其现代替代方案。
references/api.md - — UIView生命周期、组合、子类化和自定义绘制。
references/views.md - — Auto Layout、布局锚点、UIStackView、固有内容尺寸、安全区域。
references/layout.md - — UIViewController生命周期、容器控制器、避免“巨型视图控制器”。
references/controllers.md - — 导航控制器、标签栏、协调器模式、模态展示。
references/navigation.md - — 差分数据源、组合布局、单元格配置、预加载。
references/tableview-collectionview.md - — 人机界面指南、UIAppearance、特征集合、深色模式、自适应布局。
references/design.md - — VoiceOver、动态字体、无障碍特性、标签和提示。
references/accessibility.md - — 离屏渲染、图层优化、图片缓存、主线程性能。
references/performance.md - — 主线程安全、async/await、DispatchQueue迁移、后台任务。
references/concurrency.md - — 现代Swift代码、Swift并发、Objective-C互操作。
references/swift.md - — 内存管理、循环引用、KVO/通知清理、deinit模式。
references/hygiene.md