Live preview presenting app root ViewController

Hi, When running live preview on my main app target, for some reason I see the view for few moments, then it jumps back to the application root view controller.
Sometimes I get problem report screen right after.
Selectable previews works just fine.
And when I move my views to a clean module dedicated only for SwiftUI, Live previews works with no issues.

Any ideas?

Replies

When it jumps back to your applications' root view controller, is the preview interact-able at that point? If not, then the preview is showing a snapshot of the content when it first came up, and likely the app has crashed.

It would help us to take a look at the diagnostics when this happens. When you reproduce the problem in Xcode:

  1. Either (a) an error banner will appear, click the "Diagnostics" button in that banner. Or (b) if you’re not seeing an error but you still want to provide diagnostics, you can get the same diagnostics window by going under the Editor menu in the menu bar, then selecting the Canvas submenu, then selecting “Diagnostics”.

  2. In the sheet that appears, click "Generate Report" in the bottom left of the sheet

  3. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)

Hi @kcathey, thanks for the quick response.
Yes previews are intractable like in simulator.
It's an enterprise app, so I need to get legal team approval before posting logs that ,may contain sensitive data.
For now I fond 2 entry points in our code (AppDelegate) that responsible for that glitch, any way to avoid them when running live previews? I'm thinking about something like #if DEBUG for previews.

So after reading this and this I've added a new flag to our code:

static var isXcodeRunningForPreviews: Bool {
   return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
}

I wonder if this flag is robust and we can relay on it, or if there is any cleaner way to prevent some code from running when building live previews.