I did a small experiment with the following code:
@Observable
class State {
var value = 0
var isSomething = false
}
and
var state = State()
func printOnChange() {
withObservationTracking {
print("Value is now: \(state.isSomething)")
} onChange: {
printOnChange()
}
}
printOnChange()
state.isSomething = true
state.isSomething = true
state.isSomething = false
state.isSomething = false
And the output I'm getting is
Value is now: false
Value is now: false
Value is now: true
Value is now: true
Value is now: false
I thought that the on onChange was supposed to be fired only twice.
Am I getting this wrong?
I'm using the windows toolchain, by the way.