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)

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay