CloudKitSyncMonitor
CloudKitSyncMonitor copied to clipboard
"syncStateSummary" not `@Published`
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. 😅
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.
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.