#SwiftUI debugging question:

How do you inspect why Environment changes don't seem to propagate?

– I have an action in the environment (struct, usedvia `callAsAction()`). I set it up with a closure to toggle() a boolean State variable.

– I also put the State variable into the environment.

So the environment has both the toggle and a getter. It's basically a global variable.

This worked in isolation and previews, but not from the `App`.

@phill Exactly this (thanks for taking the time to write the example) is the approach I have. But for some reason it works in isolation, but not when plugged into the real app.

There are module boundaries etc., and deep view hierarchies. So I wonder why it stops working.

Follow

@ctietze I’ve noticed environment values stop being propagated in certain controls (usually Hosting/AnyView). Is the environment’s default handler being called instead of the one you’ve set? If so perhaps try explicitly setting the environment at each level to find where it breaks? Otherwise good old printChanges?

Sign in to participate in the conversation
The Not So Big Company

The home of The Not So Big Company on Mastodon.