I'm working on a SwiftUI client app for my web service. A logged-in user can belong to one or more Organizations, and in the app's settings UI, the user can change which organization is the current selectedOrg. The selected org is displayed using a Picker view in the settings UI. The Model is made available to the UI primarily through @EnvironmentObject.
When the user changes the selectedOrg, the app has to fetch some data (a set of Machine records) and set the result in the model. I see at least two ways to do this.
A) Use @State in the SwiftUI view, initialized with the current selectedOrg in the model, and .onChange(of:) that state to then call a method that sets the new org and starts the relevant data fetch.
B) Bind to the selectedOrg in the model, and use willSet/didSet inside the model to initiate the network request.
The latter option feels better, because it pulls a lot of the logic out of the views and into the model/business logic.
What are your thoughts on this?