Going through Apple SwiftUI Tutorial Landmark, Handling User Input, the LandmarkList view Preview Fail

I'm going through the Apple tutorial here: https://developer.apple.com/tutorials/swiftui/handling-user-input

At Step 7

LandmarkList preview failed, click the Diagnostic button on top of the preview canvas shows:

Landmarks.app crashed: Error Domain=render service Code=12 "Rendering service was interrupted" UserInfo={NSLocalizedDescription=Rendering service was interrupted}

The Xcode console at the bottom shows:

2019-07-11 12:40:04.071467-0700 Landmarks[6420:515507] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.

Message from debugger: Terminated due to signal 15

2019-07-11 12:40:08.380137-0700 Landmarks[6420:516007] [connection] Connection interrupted: will attempt to reconnect

The app runs fine in the simulator...

Did I just encountered a Xcode bug? Is there anything I can do to get this preview working?

Another view LandmakRow in the app preview works.

Kind of strange that everything compile, can run in simulator, one view can preview, another just fail

All the views that have @EnvironmentObject local variables fail preview. So must be Combine/BindableObject causing problem?

Yeah, you'll see this crash if you haven't attached an .environmentObject() to your preview.

They really need a specific diagnostic for this.


Yes, That was the problem. I just overlooked that line adding environmentObject() in preview.