combine-code-review

Reviews Swift Combine code for memory leaks, operator misuse, and error handling issues.

2|Updated May 25, 2026
One-click install
npx skills add https://github.com/edheltzel/Do-Skills --skill combine-code-review-edheltzel
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: combine-code-review
Source: https://github.com/edheltzel/Do-Skills/tree/main/skills/engineering/swift/do-review-ios/references/combine-code-review
Command: npx skills add https://github.com/edheltzel/Do-Skills --skill combine-code-review-edheltzel

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Combine's reactive pipelines are prone to subtle bugs: discarded AnyCancellables that silently cancel subscriptions, retain cycles from strong self captures, flatMap misuse in search flows, and error handling that kills the main chain. This Skill provides a structured review process to catch these issues before they reach production. ## Core Features & Use Cases - Memory Leak Detection: Identifies retain cycles from sink closures capturing self strongly, assign(to:on:) misuse, and discarded AnyCancellables. - Operator Correctness: Flags flatMap used where map + switchToLatest is needed, subscribe(on:) vs receive(on:) confusion, and combineLatest publishers that never emit. - Error Handling Review: Catches naked tryMap calls that erase error types, replaceError placed in the main chain, and assertNoFailure used for expected errors. - Use Case: When reviewing a SwiftUI view model that uses @Published properties and network publishers, run this review to verify every subscription is retained, weak self is used, and errors are handled inside flatMap so the main chain survives failures. ## Quick Start Review this Swift file that imports Combine and check for memory leaks, operator misuse, and error handling problems.

Frequently Asked Questions about combine-code-review

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find retain cycles in Combine sink closures?▼

Retain cycles occur when self owns the cancellable, the cancellable owns the closure, and the closure captures self strongly. Check that every sink uses [weak self] when self stores the AnyCancellable, and avoid assign(to:on:) with self since it always captures its target strongly.

When should I use flatMap vs switchToLatest in Combine?▼

Use flatMap when each transformed publisher should run to completion independently. Use map plus switchToLatest for search or autocomplete flows where a new query should cancel the previous in-flight request and prevent out-of-order results.

Why does my Combine subscription cancel immediately?▼

AnyCancellable automatically calls cancel() when deallocated, so a discarded sink result kills the subscription instantly, often surfacing as NSURLErrorDomain -999. Store every cancellable in a Set or property to keep the subscription alive.

What is the difference between PassthroughSubject and CurrentValueSubject?▼

PassthroughSubject emits only future values to subscribers and suits transient events like button taps. CurrentValueSubject requires an initial value, exposes a .value property, and replays the current value to new subscribers, making it right for state.

Does tryMap preserve the publisher's error type?▼

No, tryMap and other try-prefixed operators erase the failure type to plain Swift.Error. Follow tryMap with mapError to restore a specific error type such as APIError so downstream error handling remains typed.