DEV Community

Simran
Simran

Posted on

Short - Sheets in SwiftUI creates a new Environment

In SwiftUI we can inject objects at the environment level using .environmentObject() modifier and use them using @EnvironmentObject property wrapper. In a perfect world this environment object is available to all the subviews in that tree with certain exceptions.

One of the exceptions is that when we create a new .sheet() in any of the subviews this environment object will NOT be available for for that sheet view and its children. To use them in the sheet view and its children you would have to inject it again using .environmentObject().

Top comments (0)