swift-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Swift Code Review

Swift代码审查

Quick Reference

快速参考

Issue TypeReference
async/await, actors, Sendable, Taskreferences/concurrency.md
@Observable, @ObservationIgnored, @Bindablereferences/observable.md
throws, Result, try?, typed throwsreferences/error-handling.md
Force unwraps, retain cycles, namingreferences/common-mistakes.md
问题类型参考文档
async/await, actors, Sendable, Taskreferences/concurrency.md
@Observable, @ObservationIgnored, @Bindablereferences/observable.md
throws, Result, try?, typed throwsreferences/error-handling.md
Force unwraps, retain cycles, namingreferences/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
    async let
    or
    TaskGroup
  • 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
    LocalizedError
    with descriptive messages
  • Nested @Observable objects are also marked @Observable
  • @Bindable used for two-way bindings to Observable objects
  • 不对运行时数据(网络、用户输入、文件)使用强制解包(
    !
  • 存储为属性的闭包使用
    [weak self]
  • 代理属性标记为
    weak
  • 独立的异步操作使用
    async let
    TaskGroup
  • 长时间运行的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

审查问题

  1. Are async operations that could run concurrently using
    async let
    ?
  2. Could actor state change across suspension points (reentrancy bug)?
  3. Is
    @unchecked Sendable
    backed by actual synchronization?
  4. Are errors logged and presented with helpful context?
  5. Could any closure or delegate create a retain cycle?
  1. 可能并发运行的异步操作是否使用了
    async let
  2. Actor状态是否会在挂起点之间发生变化(重入bug)?
  3. @unchecked Sendable
    是否有实际的同步机制支持?
  4. 错误是否被记录并附带有用的上下文信息?
  5. 任何闭包或代理是否可能导致循环引用?