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

I'm going through the Apple tutorial here: Handling user input | Apple Developer Documentation

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.

3 Likes

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

Thanks!

ok, same issue here, sort of, but how do I attach the environment variable?

Are you on section 4, step 2 of the Building Lists and Navigation tutorial? (That's what it looks like to me based on your screenshot.)

If so, you haven't reached the part where you need to use environmentObject(_:) yet.

I think you're running into a bug (55670957) related to the visibility of preview provider types in newly created files. To work around it, swap out LandmarkDetail for LandmarkList where you create a hosting controller in SceneDelegate.swift, then make a clean build of the project. (Section 7, step 9 contains this same change.)

@krilnon yes, I'm at section 4, step 2, but I've never even touched my screenDelegate.swift file. And I'm new to this, so I'm not sure what to do.

Take a look at the link at the end of my last post, the blue highlighted section of the code listing section 7, step 9 is what you should try out as a fix for your error. It changes line 15 of the scene delegate to:

window.rootViewController = UIHostingController(rootView: LandmarkList())

And to make a clean build in Xcode, go to the menu and select Product > Clean Build Folder.

looks like that was on line 23 for me, but still getting the error. thanks for bearing with me

@krilnon looks like 11.1 resolved this, for now.

1 Like