# IOS State Management

> Implement reactive state with Combine, Observation framework, and UDF patterns. Use when implementing state management with Combine, @Observable, or reactive patterns in iOS.

- Skill: `hoangnguyen0403/ios-state-management` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add hoangnguyen0403/ios-state-management`
- Raw SKILL.md: https://api.skillmd.com/api/skills/hoangnguyen0403/ios-state-management/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: HoangNguyen0403 (https://skillmd.com/u/hoangnguyen0403)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/hoangnguyen0403/ios-state-management

---

# iOS State Management

## **Priority: P0 (CRITICAL)**

## Implementation Workflow

1. **Choose observation approach** — Use `@Observable` (iOS 17+) for modern SwiftUI; `Combine` with `@Published` for UIKit or broader compatibility.
2. **Expose state clearly** — Use UDF pattern: ViewModel exposes `Input` enum (events) and `Output` struct (state).
3. **Manage subscriptions** — Store Combine subscriptions in `Set<AnyCancellable>` with `.store(in: &cancellables)`.
4. **Dispatch to main thread** — Use `@MainActor` or `.receive(on: DispatchQueue.main)` for UI updates.
5. **Use exhaustive ViewState** — Prefer single `ViewState` enum (`.loading`, `.success(data)`, `.error(failure)`).

See [Combine and Observation framework examples](references/implementation.md)

## Anti-Patterns

- **No Uncleared Subscriptions**: Always use `.store(in: &cancellables)`
- **No Background UI Updates**: Use `.receive(on: .main)` or `@MainActor`
- **No Manual `objectWillChange.send()`**: Use `@Published` or `@Observable` instead

## References

- [Combine & Observation Setup](references/implementation.md)
