Nycturne
Elite Member
- Joined
- Nov 12, 2021
- Posts
- 1,392
On the Combine front, I’ve been finding more places where it is useful for drastically cutting down code.
My app has a central “engine” doing the bulk of the work but that engine needs to update various APIs that go beyond SwiftUI. So it exposes state via publishers. UI stashes the result in @State, and “plug-ins” update those other APIs as well. But each plugin can chain the publisher with other details/context to make their job easier. So supporting things in iOS like the now playing details for the Lock Screen is just a subscriber to the engine. Uploading playback state to Plex is also a subscriber.
It’s not a bad way to attach consumers of state to a producer/owner of state with minimal coupling. And is really easy to mock the publisher for whatever testing you want to do.
My app has a central “engine” doing the bulk of the work but that engine needs to update various APIs that go beyond SwiftUI. So it exposes state via publishers. UI stashes the result in @State, and “plug-ins” update those other APIs as well. But each plugin can chain the publisher with other details/context to make their job easier. So supporting things in iOS like the now playing details for the Lock Screen is just a subscriber to the engine. Uploading playback state to Plex is also a subscriber.
It’s not a bad way to attach consumers of state to a producer/owner of state with minimal coupling. And is really easy to mock the publisher for whatever testing you want to do.