#ObservableObject

Marius Kažemėkaitismarius@iosdev.space
2023-03-28

@jtaby Another thing to keep in mind is that generally, it's not a good practice to have large hierarchies of ObservableObjects. #SwiftUI is designed to have small, reusable components, easily mockable models - so all those tiny UI components can be easily previewed. Also, if the main #ObservableObject model has a Published property that is also an ObservableObject with Published properties, then the parent will not be called when something changes in the child. What we would expect by default.

Axel Le Pennecalpennec@iosdev.space
2023-03-02

When using a #NavigationStack in #SwiftUI, it seems more efficient to have the navigation path in a State passed as a Binding than using an #ObservableObject passed as an #EnvironmentObject.

According to Self._printChanges in the body of the Views, the latter redraws all the Views in the hierarchy when the path is modified (destination is appended or removed). E.g. the root View even if you are 10 Views in the #NavigationPath.

Have I missed something? 🤔

Client Info

Server: https://mastodon.social
Version: 2025.07
Repository: https://github.com/cyevgeniy/lmst