pfw-observable-models

Move Swift logic into @Observable models with async action methods.

16|2|Updated Mar 29, 2018
One-click install
npx skills add https://github.com/khoi/dotfiles --skill pfw-observable-models-khoi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pfw-observable-models
Source: https://github.com/khoi/dotfiles/tree/main/chezmoi/dot_pfw/skills/observable-models
Command: npx skills add https://github.com/khoi/dotfiles --skill pfw-observable-models-khoi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Moving Swift logic and behavior out of the UI into an @Observable model.

Core Features & Use Cases

  • Isolated logic and state in @Observable models, typically @MainActor, for easier testing and reuse.
  • Clear UI interaction through specially named methods that reflect user actions, separating concerns from views.
  • Supports dependency injection and optional presentable children via @Dependency and @ObservationIgnored to keep models testable and decoupled.

Quick Start

Create an @Observable model for your feature and expose UI actions as clearly named methods, then bind those actions from your SwiftUI view.

Frequently Asked Questions about pfw-observable-models

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

FAQPage Schema
How do I move UI logic into an observable model in SwiftUI?

To move UI logic into an observable model in SwiftUI, you extract state and behavior from your views into an @Observable model, typically isolating it on @MainActor for easier testing and reuse. This cleanly separates feature logic from view rendering.

What is the benefit of using @Observable models for iOS app architecture?

Using @Observable models for iOS app architecture isolates feature logic and state into dedicated, testable objects. This separation improves reusability and decouples business logic from SwiftUI and AppKit view rendering complexities.

How do I handle dependency injection in a Swift observable model?

Handle dependency injection in a Swift observable model by using @Dependency and @ObservationIgnored properties. This approach keeps models decoupled and testable while managing optional presentable children without triggering view updates.

Does this observable model pattern work with AppKit and macOS apps?

Yes, the observable model pattern works with AppKit and macOS apps. It applies to both SwiftUI and AppKit based applications where isolating feature logic into a dedicated model improves testability and reusability across Apple platforms.

How do I expose user actions in a Swift @Observable model?

Expose user actions in a Swift @Observable model by creating clearly named async methods that reflect specific user interactions. Bind these methods directly from your SwiftUI view to maintain a clear separation of concerns.