Swift Code Review
Review Swift code against industry best practices drawn from Google's Swift Style Guide,
Apple's API Design Guidelines, Apple's performance and memory documentation, and
real-world patterns from Apple's open-source projects.
Determine Review Scope
Figure out what to review based on the user's request:
| Request |
How to get the code |
| "Review this PR" / PR URL |
gh pr diff <number> or read the diff |
| "Review my changes" |
git diff (unstaged) and git diff --cached (staged) |
| "Review this file" / path |
Read the file(s) directly |
| "Review the codebase" |
Glob for **/*.swift files, prioritize by size/complexity |
| Xcode project review |
Also check *.xcodeproj, Package.swift, build settings |
When reviewing diffs, always read surrounding context (the full file or function) to
understand intent — don't review isolated hunks.
Review Checklist
Work through these categories in order. For each finding, cite the file, line, and
the specific guideline being violated. Skip categories that don't apply to the scope.
1. Naming & API Design
Read references/api-design.md for the complete rules.
Key checks:
- Types use
UpperCamelCase, everything else uses lowerCamelCase
- Methods read as grammatical English at the call site:
x.insert(y, at: z)
- Names describe roles, not types:
greeting not string
- Mutating/nonmutating pairs follow the
-ed/-ing convention
- Boolean properties read as assertions:
isEmpty, isValid
- Factory methods start with
make
- Protocol names use nouns for "what it is",
-able/-ible for capabilities
- Argument labels form grammatical phrases with the method name
- No abbreviations unless universally understood (
min, max, URL)
2. Code Style & Formatting
Read references/code-style.md for the complete rules.
Key checks:
- 100-character line limit
- K&R brace style (opening brace on same line)
- No semicolons
- One statement per line
// comments only, never /* */
- One variable per
let/var declaration
- Trailing commas in multiline array/dictionary literals
- Imports grouped: standard modules, then individual declarations, then
@testable
// MARK: comments to organize type members
- Shorthand syntax for arrays
[Element], dictionaries [Key: Value], optionals T?
3. Swift Patterns & Idioms
Read references/swift-patterns.md for the complete rules.
Key checks:
guard for early exits instead of nested if blocks
for-where instead of for + single if body
Optional over sentinel values (-1, empty string)
- Errors thrown, not merged with return types
- No force-unwrap (
!) without a comment explaining the invariant
- No implicitly unwrapped optionals except
@IBOutlet and test fixtures
- Explicit access control where it differs from
internal
- Nested types for scoping (error types, flag enums inside their parent)
- Prefer
let over var when value doesn't change
- Prefer value types (
struct, enum) over class when no identity needed
- Protocol extensions for default implementations, not base classes
- Computed properties omit
get when read-only
4. Build Performance
Read references/performance.md for the complete rules.
Key checks:
- No complex expressions that slow type-checker (break into smaller statements)
- Explicit types on complex closures and collection literals
- Minimize use of
AnyObject, Any — prefer concrete or generic types
- No unnecessary
@objc or dynamic unless needed for Objective-C interop
- Module boundaries are clean — no circular dependencies
- Prefer
final on classes not designed for inheritance (enables compiler optimizations)
- Large expressions broken into smaller sub-expressions with explicit types
- No excessive protocol conformance in extensions across files (merge where logical)
5. Memory Management
Read references/memory-management.md for the complete rules.
Key checks:
- No retain cycles in closures — use
[weak self] or [unowned self] appropriately
weak preferred over unowned unless lifetime is guaranteed
- Delegates declared as
weak var
- Large resources freed in
deinit or on memory warnings
- Discardable resource caches use
NSCache with count/cost limits; deterministic
maps or non-discardable data may use bounded dictionaries
- Autoreleasepool used in tight loops creating many temporary objects
- No strong reference chains between parent and child objects
- Image and data caches have size limits
- Observation tokens stored and invalidated properly
6. Testing
Read references/testing.md for the complete rules.
Key checks:
- Test methods named descriptively:
test_<condition>_<expectedResult>
- One assertion concept per test (test may have setup + multiple related asserts)
- No test interdependencies — each test stands alone
setUp() / tearDown() used for shared fixtures, not duplicated in every test
- Async code tested with expectations or Swift concurrency
- UI tests separated from unit tests
- Edge cases covered: nil, empty, boundary values, error paths
- No network calls in unit tests — use protocols and mocks
- Force-unwrap permitted in tests (fails the test if nil, which is desired)
7. Documentation
Key checks:
- Public API has
/// doc comments with summary, parameters, returns, throws
- Doc comments use verb phrases for methods, noun phrases for properties
- No
/** */ block comment syntax
Parameter, Returns, Throws tags in that order
- Complex algorithms have inline comments explaining why, not what
8. Concurrency (if applicable)
Key checks:
@Sendable closures don't capture mutable state
- Actors used for mutable shared state instead of locks
MainActor for UI updates
- No data races —
nonisolated used intentionally
- Structured concurrency (
async let, TaskGroup) preferred over unstructured Task {}
- Cancellation handled properly
Output Format
Structure the review as:
## Summary
<1-2 sentence overall assessment>
## Findings
### Critical
<issues that will cause bugs, crashes, or data loss>
### Important
<style violations, performance issues, missing tests>
### Suggestions
<minor improvements, alternative approaches>
## What's Done Well
<2-3 things the code does right — always include this>
For each finding, include:
- File and line:
Sources/Auth/TokenManager.swift:42
- Category: which checklist item it falls under
- Issue: what's wrong
- Fix: concrete code suggestion or direction
Keep findings actionable. Don't flag things that are clearly intentional project
conventions unless they cause real problems.
1---2name: swift-review3description: >4 Reviews Swift/Xcode codebases, pull requests, local changes, or individual files against5 Swift best practices including Google's Swift Style Guide, Apple's API Design Guidelines,6 build performance, memory management, and testing standards. Use this skill whenever the7 user asks to review Swift code, audit a Swift PR, check Swift style, review an Xcode8 project, or mentions swift code review, swift lint, swift best practices review, or9 swift code quality. Also trigger when reviewing .swift files, Package.swift, or Xcode10 project changes — even if the user just says "review this" or "check this code" and11 the context involves Swift.12license: MIT13metadata:14 source: https://skillmd.com/skills/bastos/swift-review15 author: github.com/bastos16 version: "1.0"17---1819# Swift Code Review2021Review Swift code against industry best practices drawn from Google's Swift Style Guide,22Apple's API Design Guidelines, Apple's performance and memory documentation, and23real-world patterns from Apple's open-source projects.2425## Determine Review Scope2627Figure out what to review based on the user's request:2829| Request | How to get the code |30|---|---|31| "Review this PR" / PR URL | `gh pr diff <number>` or read the diff |32| "Review my changes" | `git diff` (unstaged) and `git diff --cached` (staged) |33| "Review this file" / path | Read the file(s) directly |34| "Review the codebase" | Glob for `**/*.swift` files, prioritize by size/complexity |35| Xcode project review | Also check `*.xcodeproj`, `Package.swift`, build settings |3637When reviewing diffs, always read surrounding context (the full file or function) to38understand intent — don't review isolated hunks.3940## Review Checklist4142Work through these categories in order. For each finding, cite the file, line, and43the specific guideline being violated. Skip categories that don't apply to the scope.4445### 1. Naming & API Design4647Read `references/api-design.md` for the complete rules.4849Key checks:50- Types use `UpperCamelCase`, everything else uses `lowerCamelCase`51- Methods read as grammatical English at the call site: `x.insert(y, at: z)`52- Names describe roles, not types: `greeting` not `string`53- Mutating/nonmutating pairs follow the `-ed`/`-ing` convention54- Boolean properties read as assertions: `isEmpty`, `isValid`55- Factory methods start with `make`56- Protocol names use nouns for "what it is", `-able`/`-ible` for capabilities57- Argument labels form grammatical phrases with the method name58- No abbreviations unless universally understood (`min`, `max`, `URL`)5960### 2. Code Style & Formatting6162Read `references/code-style.md` for the complete rules.6364Key checks:65- 100-character line limit66- K&R brace style (opening brace on same line)67- No semicolons68- One statement per line69- `//` comments only, never `/* */`70- One variable per `let`/`var` declaration71- Trailing commas in multiline array/dictionary literals72- Imports grouped: standard modules, then individual declarations, then `@testable`73- `// MARK:` comments to organize type members74- Shorthand syntax for arrays `[Element]`, dictionaries `[Key: Value]`, optionals `T?`7576### 3. Swift Patterns & Idioms7778Read `references/swift-patterns.md` for the complete rules.7980Key checks:81- `guard` for early exits instead of nested `if` blocks82- `for-where` instead of `for` + single `if` body83- `Optional` over sentinel values (`-1`, empty string)84- Errors thrown, not merged with return types85- No force-unwrap (`!`) without a comment explaining the invariant86- No implicitly unwrapped optionals except `@IBOutlet` and test fixtures87- Explicit access control where it differs from `internal`88- Nested types for scoping (error types, flag enums inside their parent)89- Prefer `let` over `var` when value doesn't change90- Prefer value types (`struct`, `enum`) over `class` when no identity needed91- Protocol extensions for default implementations, not base classes92- Computed properties omit `get` when read-only9394### 4. Build Performance9596Read `references/performance.md` for the complete rules.9798Key checks:99- No complex expressions that slow type-checker (break into smaller statements)100- Explicit types on complex closures and collection literals101- Minimize use of `AnyObject`, `Any` — prefer concrete or generic types102- No unnecessary `@objc` or `dynamic` unless needed for Objective-C interop103- Module boundaries are clean — no circular dependencies104- Prefer `final` on classes not designed for inheritance (enables compiler optimizations)105- Large expressions broken into smaller sub-expressions with explicit types106- No excessive protocol conformance in extensions across files (merge where logical)107108### 5. Memory Management109110Read `references/memory-management.md` for the complete rules.111112Key checks:113- No retain cycles in closures — use `[weak self]` or `[unowned self]` appropriately114- `weak` preferred over `unowned` unless lifetime is guaranteed115- Delegates declared as `weak var`116- Large resources freed in `deinit` or on memory warnings117- Discardable resource caches use `NSCache` with count/cost limits; deterministic118 maps or non-discardable data may use bounded dictionaries119- Autoreleasepool used in tight loops creating many temporary objects120- No strong reference chains between parent and child objects121- Image and data caches have size limits122- Observation tokens stored and invalidated properly123124### 6. Testing125126Read `references/testing.md` for the complete rules.127128Key checks:129- Test methods named descriptively: `test_<condition>_<expectedResult>`130- One assertion concept per test (test may have setup + multiple related asserts)131- No test interdependencies — each test stands alone132- `setUp()` / `tearDown()` used for shared fixtures, not duplicated in every test133- Async code tested with expectations or Swift concurrency134- UI tests separated from unit tests135- Edge cases covered: nil, empty, boundary values, error paths136- No network calls in unit tests — use protocols and mocks137- Force-unwrap permitted in tests (fails the test if nil, which is desired)138139### 7. Documentation140141Key checks:142- Public API has `///` doc comments with summary, parameters, returns, throws143- Doc comments use verb phrases for methods, noun phrases for properties144- No `/** */` block comment syntax145- `Parameter`, `Returns`, `Throws` tags in that order146- Complex algorithms have inline comments explaining why, not what147148### 8. Concurrency (if applicable)149150Key checks:151- `@Sendable` closures don't capture mutable state152- Actors used for mutable shared state instead of locks153- `MainActor` for UI updates154- No data races — `nonisolated` used intentionally155- Structured concurrency (`async let`, `TaskGroup`) preferred over unstructured `Task {}`156- Cancellation handled properly157158## Output Format159160Structure the review as:161162```163## Summary164<1-2 sentence overall assessment>165166## Findings167168### Critical169<issues that will cause bugs, crashes, or data loss>170171### Important172<style violations, performance issues, missing tests>173174### Suggestions175<minor improvements, alternative approaches>176177## What's Done Well178<2-3 things the code does right — always include this>179```180181For each finding, include:182- **File and line**: `Sources/Auth/TokenManager.swift:42`183- **Category**: which checklist item it falls under184- **Issue**: what's wrong185- **Fix**: concrete code suggestion or direction186187Keep findings actionable. Don't flag things that are clearly intentional project188conventions unless they cause real problems.