Lifecycle of SwiftUI View - @Observable vs ObservableObject

I think I figured out the answer.

Which is NO.

onChange() does not recreate the view. However, onChange() makes/requires dependency to the value. And changes of the value evoke the refresh of the view, therefore the recreate of the children view. onChange() is tied to a dependency.

onReceive() responds to an event emitted by the publisher, which doesn't create a state dependency on the view. Therefore, changes in the value of the @Published variable do not affect the view and its recreation, and the children where the onReceive() is used.

In other words, the recreation of the view happens before the onChange() closure is executed. This is why even an empty onChange() seems to have an effect on the view.

So technically onChange() itself doesn’t recreates the view, but practically using onChange() does, since it requires mutable value in a struct, to make it practical, has to be anything observable.

2 Likes