Skillshub ios-state-management
Standards for Combine, Observation, and Reactive Programming. Use when managing state with Combine, @Observable, or reactive patterns in iOS. (triggers: **/*.swift, Observable, @Published, PassthroughSubject, @Observable, @Namespace)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/ios-state-management" ~/.claude/skills/comeonoliver-skillshub-ios-state-management && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/ios-state-management/SKILL.mdsource content
iOS State Management Standards
Priority: P0
Implementation Guidelines
Combine (Reactive States)
- Publishers: Use
for standard state in ViewModels. Use@Published
for one-time navigation or alert events.PassthroughSubject - Memory Management: Store subscriptions in a
. UseSet<AnyCancellable>
to prevent memory leaks and ensure they are cleared on deinit..store(in: &cancellables) - Operators: Use specific operators like
,.debounce
,.filter
, and.map
to handle complex input streams..flatMap - Schedulers: Always ensure UI property updates occur on the main thread using
or@MainActor
..receive(on: DispatchQueue.main)
Observation Framework (iOS 17+)
: Use the@Observable
macro for modern, high-performance observation in SwiftUI.@Observable- State Properties: In SwiftUI views, use
for two-way bindings with@Bindable
objects.@Observable - Namespaces: Use
for match-geometry animations and coordinate space tracking.@Namespace
Unidirectional Data Flow (UDF)
- Input/Output: ViewModels should expose an
enum (events) andInput
struct (state) to enforce a clear data direction.Output - ViewState: Prefer a single, exhaustive
enum (e.g.,ViewState
,.loading
,.success(data)
)..error(failure)
Anti-Patterns
- No uncleared subscriptions: Always use .store(in: &cancellables).
- No UI updates on background: Use .receive(on: .main).
- No manual objectWillChange: Use @Published or @Observable.