Xcode 12 Beta "Cannot preview in this file"

Hi there!

I've been messing around in Xcode 12 Beta with SwiftUI and a Core Data Model, and for some reason my ContentView preview in Xcode is failing to load. Here's the error:

"Cannot preview in this file — Connection interrupted: send message to agent"

I've made sure all my target memberships are synchronized, given Xcode 12 Command Line Tools in Preferences>Locations, and tried every other solution I can find out there.

Any ideas?

Replies

Could you please file a feedback and include a sysdiagnose? https://feedbackassistant.apple.com

Please reproduce the crash and hold down shift, control, alt, command and press . (period). Your screen will flash and a finder window will open about 15-30 seconds later. Attach the zipped file to your feedback. It helps us track down the issue.
a feedback report will be the best way for us to help you. For preview issues specifically we will need the diagnostics Xcode Previews generates in order to make sure we understand the error the previews system is encountering.
  1. When you get an error in Xcode Previews, an error banner appears in the canvas

  2. Click the "Diagnostics" button in that banner

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

  4. Attach the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)

Same issue for me. I filed FB7829539.
I was experiencing the same issue. I found it to be caused by this line:

Code Block swift
@SceneStorage("selectedItem") var selectedItem: String?


Removing it allowed the preview to show again.

Hope this helps.
  • What did you replace it with?

Add a Comment
I had an error in the code where an array index was out of bounds. When I fixed that, the preview showed up. That said, the weird error message wasn't helpful.
Okay, I'd love to send along the previews-diagnostics-

file, but I am not seeing any file when I click 'Generate Report'. When I click 'Generate Report, Xcode 12. v2 kicks me to a finder screen with a long directory (perhaps temp folder? I'm not sure...). Nowhere in the list is anything titled 'previews-diagnostics'. I have no idea where to find the file,



I've been getting the same error for a while. I found first of all that I hadn't included all the .environmentalObjects that I should have, but then after I corrected that I still had the problem. After analysing the problem I removed the networking lawyer code (one file) and the problem was corrected. Later I added the code back and the problem returned, so I removed it again… and the problem stayed. Then I used Time Machine to restore the working code… and the problem still remained.

What am I missing?

I received the same error. In my case, closing and reopening the project fixed the problem.

Any update here? I'm encountering the same issue on my end. @nlweeks

  • Closing and reopening the project.

Add a Comment