Is it wise to have a single state as an environment object for the whole SwiftUI app?

55 Views Asked by At

I've been looking at different ways to build in deeplinking capabilities for a SwiftUI app using NavigationSatck. Some articles suggest having the navigation state injected as an environment object like below

class NavigationState: ObservableObject {
    @Published var navigationPath = NavigationPath()
}

We can then inject this into the root view of the app as an environment object and have the NavigationStack be driven by the navigationPath.

By doing this, we can handle deeplinking by appending the relevant paths to this navigationPath and it all seems to work fine.

But since all views now depend on this environment object, just by pushing a new view, won't it redraw all the views before it in the view hierarchy and for a large app with multiple screens won't that lead to performance issues?

0

There are 0 best solutions below