axiom-combine-patterns
БесплатноБез исполняемых скриптовНе проверенUse when working with Combine publishers, AnyCancellable lifecycle, @Published properties, or bridging Combine with async/await. Covers reactive patterns…
от ComeOnOliver★ 67 звёзд на GitHubОб этом скилле
Combine Patterns
Overview
Combine remains embedded in massive production codebases — UIKit delegates, NotificationCenter bridging, KVO observation, and @Published properties are everywhere. New code prefers async/await, but interop and maintenance of existing Combine pipelines is daily work. This skill covers the decisions and pitfalls that matter: when to use Combine vs async/await, how to avoid memory leaks, and how to bridge between the two paradigms.
Core principle: Combine is not dead — it's mature. The question isn't "should I use Combine?" but "is Combine the right tool for THIS specific data flow?"
When to Use This Skill
- Working with existing Combine pipelines
- Deciding between Combine and async/await for a new data flow
- Debugging AnyCancellable memory leaks or silent pipeline failures
- Using @Published or ObservableObject
- Bridging Combine publishers with async/await code
- Working with Subjects (PassthroughSubject, CurrentValueSubject)
When NOT to Use This Skill
- Timer.publish patterns → route via
axiom-ios-concurrencyto timer-patterns skill (dedicated timer lifecycle coverage) - @Observable migration from ObservableObject → use
axiom-swift-concurrency(modern observation) - UIKit ↔ SwiftUI bridging → route via
axiom-ios-ui(view wrapping, not data flow) - General async/await patterns → use
axiom-swift-concurrency
Example Prompts
- "Should I use Combine or async/await for this?"
- "My Combine pipeline silently stops producing values"
- "How do I convert a publisher to an async sequence?"
- "AnyCancellable is leaking — where do I store it?"
- "What's the difference between combineLatest and zip?"
- "How do I debounce a text field with Combine?"
- "My @Published property update isn't reaching the view"
- "How do I bridge a Combine publisher into async/await code?"
Part 1: Combine vs async/await Decision Tree
| Use Case | Combine | async/await | Why |
|---|---|---|---|
| One-shot network call | No | Yes | async/await is simpler, no cancellable management |
| Stream of values over time | Yes | AsyncStream | Combine's operators (debounce, combineLatest) are richer |
| Debounce/throttle user input | Yes | Awkward | Combine has built-in debounce/throttle; AsyncStream requires manual implementation |
| Merge multiple sources | Yes | TaskGroup | Combine's merge/combineLatest handle heterogeneous streams naturally |
| Existing UIKit KVO/Notification | Yes | Bridge | publisher(for:) and NotificationCenter.default.publisher are idiomatic Combine |
| New project iOS 17+ | No | Yes | @Observable + async/await is the modern pattern |
| Existing codebase with Combine | Maintain | Migrate incrementally | Don't rewrite working pipelines — bridge at boundaries |
Quick Decision
Is it a one-shot operation (network call, file read)?
├─ Yes → async/await (simpler, no cancellable management)
│
Does it need time-based operators (debounce, throttle, delay)?
├─ Yes → Combine (built-in operators, no manual implementation)
│
Are you combining multiple ongoing streams?
├─ Yes → Combine (combineLatest, merge, zip are purpose-built)
│
Is this new code on iOS 17+?
├─ Yes → async/await + @Observable (modern pattern)
│
Is it existing Combine code that works?
└─ Yes → Keep it. Bridge at boundaries when async/await code needs the data.
Part 2: Publisher/Subscriber Lifecycle
AnyCancellable Storage Rules
AnyCancellable cancels its subscription when deallocated. If you don't store it, the pipeline is cancelled immediately after setup.
❌ Pipeline dies instantly
func setupPipeline() {
publisher
.sink { value in
self.handle(value) // Never called
}
// AnyCancellable returned by sink is discarded → subscription cancelled
}
✅ Store in Set
private var cancellables = Set<AnyCancellable>()
func setupPipeline() {
publisher
.sink { [weak self] value in
self?.handle(value)
}
.store(in: &cancellables)
}
Why Set, Not Array
Set<AnyCancellable> is the idiomatic choice because:
store(in:)works with bothSetandRangeReplaceableCollection(includingArray), butSetis conventional- Order doesn't matter for subscriptions
- Prevents accidental duplicates if setup runs twice
4 Memory Leak Patterns
Leak 1: Strong self in sink
// ❌ LEAK: sink closure captures self strongly
publisher
.sink { value in
self.handle(value) // Strong capture → retain cycle
}
.store(in: &cancellables)
// ✅ FIX: weak self
publisher
.sink { [weak self] value in
self?.handle(value)
}
.store(in: &cancellables)
Leak 2: Missing store(in:)
// ❌ LEAK: cancellable assigned to local var, not stored
let cancellable = publisher.sink { handle($0) }
// cancellable deallocated at end of scope → pipeline cancelled
// ✅ FIX: store in instance property
publi
Установить axiom-combine-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл axiom-combine-patterns?
Use when working with Combine publishers, AnyCancellable lifecycle, @Published properties, or bridging Combine with async/await. Covers reactive patterns, operator selection, memory management, and migration strategy.
Как установить скилл axiom-combine-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл axiom-combine-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic