Silently Update Published Data

I have an observable object in SwiftUI with multiple published properties. When my app starts I want to update the values of all of these properties by making an API call. That is easy, and I have managed that.

However, every time one of these property changes, I make an update API call to the backend. For ease of use, I do any update to any of these properties will update all of the properties on the backend.

The problem is the beginning. How do I "silently" update the individual properties in the first API call without setting off the published chain of events that update "all" of the API calls. This obviously leads to a problem since my initial state has several blank fields that would get overwritten in the backend.

Basically, is there a way to update a "Published" value without triggering the publish subscription call?

I'm not sure that I fully understand what you're doing and how you're doing it. However, I've a couple of apps that have numerous variables in my Data Store (backend?) updated by async methods (e.g. BLE devices) and prefer not to overload my SwiftUI Views with extraneous updates. I therefore use the Combine Framework to publish an object when it's ready for display e.g. in my Data Store  public let transactionAdded = PassthroughSubject<(Transaction), Never>(). Then when appropriate, in my Data Store code, I publish the object e.g. transactionAdded.send(newTransaction)

In my SwiftUI View I use .onReceive to listen for the published object and do whatever is necessary e.g. .onReceive((dataStore.transactionAdded), perform: { transaction in .......}. The perform usually needs to trigger a View refresh, e.g. by setting/updating a @State variable.

That said, Combine can update values in the store without triggering view updates, and/or chain async results before then informing views.

Dunno if this helps. Cheers, Michaela

Silently Update Published Data
 
 
Q