搜索

PythonReactSEOPDF
GitHub Skill

ios-state-management

Standards for Combine, Observation, and Reactive Programming. Use when managing state with Combine, @Observable, or reactive patterns in iOS.

HoangNguyen0403☆ 305 仓库 Stars90 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

iOS State Management Standards

Priority: P0

Implementation Guidelines

Combine (Reactive)
  • Publishers: Use @Published for state in ViewModels. Use PassthroughSubject for one-time events (Transitions/Alerts).
  • Memory Management: Store subscriptions in a Set<AnyCancellable>. Ensure they are cleared on deinit.
  • Operators: Use operators like .debounce, .filter, .map, and .flatMap to transform input stream.
  • Schedulers: Always prefix UI property updates with @MainActor or use .receive(on: DispatchQueue.main).
Observation Framework (iOS 17+)
  • @Observable: Use for modern, macro-based observation. Replace ObservableObject in SwiftUI apps.
  • Binding: Use $state for two-way bindings in SwiftUI. No boilerplate objectWillChange calls.
Best Practices
  • ViewState Unification: Prefer a single State enum or struct (Unidirectional) for complex screens.
  • Avoid Over-Reactive: Don't use Combine for simple local flags. Use standard @State or variables.

Anti-Patterns

  • Subscription Leaks: **No uncleared subscriptions**: Always use .store(in: &cancellables).
  • Main Thread Violation: **No UI updates on Background**: Use .receive(on: .main).
  • Manual objectWillChange: **No manual notifications**: Use @Published or @Observable.

References

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-03-11
索引更新时间
2026-03-11
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!