I created a finance tracking app. I wanted to use HistoryObserver to determine when Transactions are created/updated/deleted on another device with the same appleId, so I can update some charts
I have an @Observable model that has this (simplified) setup:
private(set) var transactionObserver: HistoryObserver?
func setupHistoryObserver(modelContainer: ModelContainer) throws {
transactionObserver = try HistoryObserver(
observedModels: [Transaction.self],
modelContainer: modelContainer,
)
}
var transactionUpdateTrigger: Int {
transactionObserver?.eventCounter ?? 0
}
I have the view setup with:
.task(id: viewModel.transactionUpdateTrigger) {
print("updating chart data: \(viewModel.transactionUpdateTrigger)")
await updateChartData()
}
When I launch my app on my iPhone, I see:
updating chart data: 0
updating chart data: 1
updating chart data: 2
updating chart data: 3
updating chart data: 4
updating chart data: 5
updating chart data: 6
updating chart data: 7
updating chart data: 8
updating chart data: 9
updating chart data: 10
On simulator, it only fires once:
updating chart data: 0
The docs state: "When relevant changes are detected, the observer updates its eventCounter property."
The happens every single time I try deploying my app to my iPhone on iOS 27 beta 8, but with varying numbers of eventCounter increments. I only have the app installed on a single device with my Apple Account.
Why is this happening? There should be no changes to my models, as is clear because there's no issues when running this in simulator.