uikit-max

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Review 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:
  1. Check for deprecated API using
    references/api.md
    .
  2. Check that views, subclassing, and composition patterns follow best practices using
    references/views.md
    .
  3. Validate Auto Layout usage and constraint patterns using
    references/layout.md
    .
  4. Ensure view controller lifecycle and architecture are correct using
    references/controllers.md
    .
  5. Ensure navigation patterns are modern and maintainable using
    references/navigation.md
    .
  6. Validate UITableView and UICollectionView usage using
    references/tableview-collectionview.md
    .
  7. Ensure the code uses designs that are accessible and compliant with Apple's Human Interface Guidelines using
    references/design.md
    .
  8. Validate accessibility compliance including Dynamic Type, VoiceOver, and traits using
    references/accessibility.md
    .
  9. Ensure the code runs efficiently using
    references/performance.md
    .
  10. Check concurrency and thread safety using
    references/concurrency.md
    .
  11. Quick validation of Swift code using
    references/swift.md
    .
  12. Final code hygiene check using
    references/hygiene.md
    .
If doing a partial review, load only the relevant reference files.
审查Swift和UIKit代码的正确性、现代API使用情况以及是否符合项目规范。仅报告真实存在的问题——不要吹毛求疵或捏造问题。
审查流程:
  1. 使用
    references/api.md
    检查已弃用的API。
  2. 使用
    references/views.md
    检查视图、子类化和组合模式是否遵循最佳实践。
  3. 使用
    references/layout.md
    验证Auto Layout的使用和约束模式。
  4. 使用
    references/controllers.md
    确保视图控制器的生命周期和架构正确。
  5. 使用
    references/navigation.md
    确保导航模式现代化且易于维护。
  6. 使用
    references/tableview-collectionview.md
    验证UITableView和UICollectionView的使用。
  7. 使用
    references/design.md
    确保代码采用符合Apple人机界面指南的可访问设计。
  8. 使用
    references/accessibility.md
    验证无障碍合规性,包括动态字体、VoiceOver和特性设置。
  9. 使用
    references/performance.md
    确保代码高效运行。
  10. 使用
    references/concurrency.md
    检查并发和线程安全性。
  11. 使用
    references/swift.md
    快速验证Swift代码。
  12. 使用
    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
    if #available
    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.
  • 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包装在
    if #available
    检查中。参考文件会标记关键API的iOS版本要求(例如“iOS 15+”)。在未提供回退方案的情况下,不要建议使用项目最低目标版本不支持的API。
  • 作为UIKit开发者,用户期望使用UIKit模式。除非明确要求,否则不要建议替换为SwiftUI。
  • 未经询问,不要引入第三方框架。
  • 将不同类型拆分到不同的Swift文件中,不要将多个类、结构体或枚举放在单个文件里。
  • 使用一致的项目结构,根据应用功能确定文件夹布局。
  • 对于新代码,优先使用带Auto Layout锚点的程序化UI,而非Storyboards和XIBs,除非项目已广泛使用Interface Builder。

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
    UIAlertController
    instead of
    UIAlertView
    ").
  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. 指出违反的规则(例如“使用
    UIAlertController
    替代
    UIAlertView
    ”)。
  3. 展示简短的修复前后代码对比。
跳过无问题的文件。最后列出优先级最高的关键修改建议。
示例输出:

ProfileViewController.swift

ProfileViewController.swift

Line 8: Use
UIAlertController
instead of deprecated
UIAlertView
.
swift
// 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.activate
.
swift
// 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
translatesAutoresizingMaskIntoConstraints = false
before adding constraints.
swift
// 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行:使用
UIAlertController
替代已弃用的
UIAlertView
swift
// 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.activate
批量激活约束。
swift
// 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 = false
swift
// 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

总结

  1. Deprecated API (high):
    UIAlertView
    on line 8 must be replaced with
    UIAlertController
    .
  2. Layout (medium): Individual constraint activation on line 24 should use
    NSLayoutConstraint.activate
    .
  3. Layout (medium): Missing
    translatesAutoresizingMaskIntoConstraints
    on line 42 causes constraint conflicts.
End of example.
  1. 已弃用API(高优先级):第8行的
    UIAlertView
    必须替换为
    UIAlertController
  2. 布局(中优先级):第24行的单个约束激活应使用
    NSLayoutConstraint.activate
  3. 布局(中优先级):第42行缺少
    translatesAutoresizingMaskIntoConstraints
    会导致约束冲突。
示例结束。

References

参考资料

  • references/api.md
    — deprecated UIKit APIs and their modern replacements.
  • references/views.md
    — UIView lifecycle, composition, subclassing, and custom drawing.
  • references/layout.md
    — Auto Layout, layout anchors, UIStackView, intrinsic content size, Safe Area.
  • references/controllers.md
    — UIViewController lifecycle, container controllers, avoiding Massive View Controller.
  • references/navigation.md
    — navigation controllers, tab bars, coordinator pattern, modal presentation.
  • references/tableview-collectionview.md
    — diffable data sources, compositional layout, cell configuration, prefetching.
  • references/design.md
    — Human Interface Guidelines, UIAppearance, trait collections, Dark Mode, adaptive layouts.
  • references/accessibility.md
    — VoiceOver, Dynamic Type, accessibility traits, labels, and hints.
  • references/performance.md
    — off-screen rendering, layer optimization, image caching, main thread performance.
  • references/concurrency.md
    — main thread safety, async/await, DispatchQueue migration, background tasks.
  • references/swift.md
    — modern Swift code, Swift concurrency, Objective-C interop.
  • references/hygiene.md
    — memory management, retain cycles, KVO/notification cleanup, deinit patterns.
  • references/api.md
    — 已弃用的UIKit API及其现代替代方案。
  • references/views.md
    — UIView生命周期、组合、子类化和自定义绘制。
  • references/layout.md
    — Auto Layout、布局锚点、UIStackView、固有内容尺寸、安全区域。
  • references/controllers.md
    — UIViewController生命周期、容器控制器、避免“巨型视图控制器”。
  • references/navigation.md
    — 导航控制器、标签栏、协调器模式、模态展示。
  • references/tableview-collectionview.md
    — 差分数据源、组合布局、单元格配置、预加载。
  • references/design.md
    — 人机界面指南、UIAppearance、特征集合、深色模式、自适应布局。
  • references/accessibility.md
    — VoiceOver、动态字体、无障碍特性、标签和提示。
  • references/performance.md
    — 离屏渲染、图层优化、图片缓存、主线程性能。
  • references/concurrency.md
    — 主线程安全、async/await、DispatchQueue迁移、后台任务。
  • references/swift.md
    — 现代Swift代码、Swift并发、Objective-C互操作。
  • references/hygiene.md
    — 内存管理、循环引用、KVO/通知清理、deinit模式。