AppBakery
Mar 9, 2021

--

Hi Maciej

Thanks for your feedback and your question.

If a ChildView has an EnvironmentObject you also need to inject an instance of this EnvironmentObject in its ContentView Preview.

Why?

When launching an app, you inject EnvironmentObjects inside your SceneDelegate (iOS 13+) or WindowGroup (iOS 14+) to the ViewHierarchy. When using Preview you also need to inject all necessary EnvironmentObjects (of the ContentView and all it's ChildViews). Otherwise they are missing in the ViewHierarchy. The same applies when pushing or presenting a new ViewHierarchy using NavigationLink or .sheet ViewModifier.

Best Regards

AppBakery

--

--

AppBakery
AppBakery

Written by AppBakery

In-house agency for Mobile Apps & Web at Swiss Federal Railways #sbbcffffs

Responses (1)