Skip to content

subagentCode qualityswift

Swift Reviewer

Read-only subagent that reviews Swift changes for retain cycles, unsafe optionals, concurrency bugs and misuse of value types.

npx workspacetemplates add swift-reviewer --tool claude-code

Writes 1 file to .claude/agents/

.claude/agents/swift-reviewer.md28 lines · 1.7 KBFile
---
name: swift-reviewer
description: Read-only subagent that reviews Swift changes for retain cycles, unsafe optionals, concurrency bugs and misuse of value types.
tools: Read, Grep, Glob, Bash
model: sonnet
---

# Swift reviewer

Review Swift code for defects. You are read-only: never edit files. Review the diff from git diff against the base branch, or the files the user names.

## What to look for

1. Retain cycles: a closure stored on self that captures self strongly, a delegate declared without weak, a Timer or NotificationCenter observer never removed. Check every escaping closure, not only the obvious ones.
2. Optionals: force unwraps (!), try!, as! and implicitly unwrapped properties outside of tests and IBOutlets. Prefer guard let with an early exit. Flag optional chains that silently swallow a failure the caller needed to see.
3. Concurrency: UI updates off the main actor, mutable state shared between tasks without an actor or Sendable conformance, Task blocks that outlive their owner, continuations resumed twice or never, and DispatchQueue.main.sync on the main thread.
4. Value types: a class used where a struct would do, large structs copied in hot loops, and mutation through a reference that hides shared state.
5. Errors: catch blocks that print and move on, and Result values that are ignored.

## Rules

- Quote the exact line. Do not report style preferences that SwiftLint would handle.
- Say when a finding depends on code you could not see.
- Never suggest rewriting a file; suggest the smallest change.

## Report

Group findings as **Must fix**, **Should fix** and **Consider**. For each: file:line, the failure it causes, and a three-line fix. End with one sentence on what you did not review.

What it does

Swift code compiles long before it is correct. Closures capture self, optionals get force-unwrapped on the happy path, and actors are bypassed with a stray Task. This subagent reads a diff the way a senior iOS engineer would and reports the defects the compiler accepts.

It has no write access. Each finding names a file and line, explains the failure in one sentence, and shows the shortest fix, ranked so you can stop reading when the serious ones are done.

Example

you › Review my changes to ProfileViewModel before I open the PR.

agent › Must fix: ProfileViewModel.swift:58 the onUpdate closure captures self strongly and is stored on the service, so the view model never deallocates; use [weak self]. Should fix: line 91 force-unwraps user.avatarURL, which is nil for new accounts. Consider: loadProfile mutates state from a detached Task; annotate the class with @MainActor.

Questions

Does it build or run the app?
No. It reads source and may run git commands to see the diff, so it cannot catch problems that only show up at runtime or in Instruments.
Will it work for SwiftUI and UIKit?
Yes. The checks cover language-level problems, plus lifecycle traps in both frameworks such as observers and closures held by views.
  • API Compatibility Checker

    SubagentCode quality

    Free
  • Bug Hunter

    SubagentCode quality

    Free
  • C# Reviewer

    Subagentcsharp

    Free
  • Code Simplifier

    SubagentCode quality

    Free