swift-code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSwift Code Review
Swift代码审查
Quick Reference
快速参考
| Issue Type | Reference |
|---|---|
| async/await, actors, Sendable, Task | references/concurrency.md |
| @Observable, @ObservationIgnored, @Bindable | references/observable.md |
| throws, Result, try?, typed throws | references/error-handling.md |
| Force unwraps, retain cycles, naming | references/common-mistakes.md |
| 问题类型 | 参考文档 |
|---|---|
| async/await, actors, Sendable, Task | references/concurrency.md |
| @Observable, @ObservationIgnored, @Bindable | references/observable.md |
| throws, Result, try?, typed throws | references/error-handling.md |
| Force unwraps, retain cycles, naming | references/common-mistakes.md |
Review Checklist
审查检查清单
- No force unwraps () on runtime data (network, user input, files)
! - Closures stored as properties use
[weak self] - Delegate properties are
weak - Independent async operations use or
async letTaskGroup - Long-running Tasks check
Task.isCancelled - Actors have mutable state to protect (no stateless actors)
- Sendable types are truly thread-safe (beware )
@unchecked - Errors handled explicitly (no empty catch blocks)
- Custom errors conform to with descriptive messages
LocalizedError - Nested @Observable objects are also marked @Observable
- @Bindable used for two-way bindings to Observable objects
- 不对运行时数据(网络、用户输入、文件)使用强制解包()
! - 存储为属性的闭包使用
[weak self] - 代理属性标记为
weak - 独立的异步操作使用或
async letTaskGroup - 长时间运行的Task检查
Task.isCancelled - Actor具有需要保护的可变状态(无状态Actor不允许)
- Sendable类型真正实现线程安全(注意)
@unchecked - 显式处理错误(无空catch块)
- 自定义错误遵循并包含描述性消息
LocalizedError - 嵌套的@Observable对象也标记为@Observable
- 对Observable对象的双向绑定使用@Bindable
When to Load References
何时加载参考文档
- Reviewing async/await, actors, or TaskGroups → concurrency.md
- Reviewing @Observable or SwiftUI state → observable.md
- Reviewing error handling or throws → error-handling.md
- General Swift review → common-mistakes.md
- 审查async/await、actors或TaskGroups → concurrency.md
- 审查@Observable或SwiftUI状态 → observable.md
- 审查错误处理或throws → error-handling.md
- 通用Swift代码审查 → common-mistakes.md
Review Questions
审查问题
- Are async operations that could run concurrently using ?
async let - Could actor state change across suspension points (reentrancy bug)?
- Is backed by actual synchronization?
@unchecked Sendable - Are errors logged and presented with helpful context?
- Could any closure or delegate create a retain cycle?
- 可能并发运行的异步操作是否使用了?
async let - Actor状态是否会在挂起点之间发生变化(重入bug)?
- 是否有实际的同步机制支持?
@unchecked Sendable - 错误是否被记录并附带有用的上下文信息?
- 任何闭包或代理是否可能导致循环引用?