"Cannot show preview" message in Preview window

I'm trying to preview a SwiftUI view that resides in a local Swift package. I have the Swift package selected as the current scheme, so all the proper dependencies are available and the build succeeds. But I see this message in the Preview window:

Cannot show preview: check whether the preview is compiled for the current scheme and OS of the device used for previewing

How do I ensure the preview is compiled for a particular scheme and device OS?

I updated MacOS to 14.3.1 and Xcode to 15.3 in the hopes that that might fix this issue, but it did not.

Replies

Hi,

Sorry to hear you are having problems getting previews working. The best next step will be to file a feedback with diagnostics so we can investigate..

Steps to generate helpful diagnostics:

  1. Download and install the logging profile on all devices involved. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift
  2. Reproduce the issue
  3. Click the "Diagnostics" button in the error banner in Previews' Canvas area (or if the banner is missing you can use the menu: Editor > Canvas > Diagnostics)
  4. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  5. Attach (or make from the folder) the resulting zip file to the bug report (will be named something like previews-diagnostics-0123456789.zip)
  6. Generate the sysdiagnose(s) and attach those too

Sorry for the trouble. Looks like there was a conditional dependency registration that was not getting triggered for me. That was causing this issue. Fixing the logic fixed the Preview.