#EnvironmentObject

Benediktbenjidea
2024-08-24

I am currently experimenting with saving a single AppSettings instance in SwiftData & synchronizing it to all devices.
However, SwiftData mainly works with queries for many objects. This would result in a query in each view and a problem with optionals due to “settings?.first”.

My approach right now is to handle it centrally and pass it on as an environmentObject.
Do you have any experience or ideas on this approach?

Code snippet displaying a SwiftUI application structure, including a main `App` struct and a `DataController` class for managing app settings and model container.
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