@Observable: Shared State That Announces Changes

When state outgrows the view

The Walkers screen shows a list fetched from the backend. That involves real logic: start a request, handle success, handle failure. Stuffing all of that into a view's body gets ugly fast β€” and the view can't be the only thing that ever needs the data.

The PawWalk pattern is a view model: a class that owns a screen's data and the logic around it. The view's only job is to display whatever the view model says. It's a class β€” a reference type β€” because everyone who looks at it must see the same one object, not a copy.

One problem remains: when a property of a plain class changes, SwiftUI has no idea. Enter @Observable β€” a macro from the Observation framework (iOS 17+). A macro is an annotation that writes boilerplate for you at compile time; this one makes the class announce its changes. SwiftUI then tracks exactly which properties each view reads, and re-renders a view only when one of those changes.