CloudKitSyncMonitor icon indicating copy to clipboard operation
CloudKitSyncMonitor copied to clipboard

"syncStateSummary" not `@Published`

Open benguild opened this issue 1 year ago • 4 comments

I was looking at this library and noticed that this property, although useful, is not @Published.... So, in order to catch changes on it, one would need to monitor changes to a half dozen or so other properties.

It seems potentially wasteful (although not terribly) to calculate this in advance for publishing if not used, but it's also a hassle to monitor so many other properties.

Just wanted to ask if there was potentially a compromise here, or if you had best practices in mind regarding this. 😅

benguild avatar Sep 12 '23 17:09 benguild

Hi @benguild,

The SyncMonitor class itself is an ObservableObject, so any property you include in a SwiftUI View (assuming you're using SwiftUI) will be updated when there's a change. You'll notice that the @Published properties in SyncMonitor are all private.

So, if you do:

@ObservedObject var syncMonitor: SyncMonitor = SyncMonitor.shared

then in your View include

syncmonitor.syncStateSummary

Then syncStateSummary will be updated when the sync state changes because syncMonitor itself will show that a change was published.

ggruen avatar Sep 18 '23 20:09 ggruen

Sorry for the delay! So, I guess the downside there is it'd recalculate the view whenever anything changes, even outside of the visual linked to "syncStateSummary" ...?

In this case it might be OK, but in others it might be less ideal depending on what's going on.

benguild avatar Sep 23 '23 10:09 benguild