Xcode Previews no longer update after changes to outside files

Xcode SwiftUI previews were a godsend, increasing my productivity by 1000x with use cases like this:

  • Preview a UIViewController (via UIViewControllerRepresentable)
  • Update view controller code and see changes to previews in real time
  • Update theme files (colors, styles) and see changes to previews in real time

This all used to work like a charm as long as the updated code was inside functions or computed properties. But starting with Xcode 13.2, it no longer works:

  • Updating any file outside of PreviewProvider struct just reloads the canvas, but does not account for changes in these files (e.g. if I change color in a theme file, the old color will be shown in preview until I pause the preview, recompile and reload preview)
  • Using "Refresh Canvas" does not solve the issue (it just reloads the canvas with stale data)

Any way to fix this?

Hi,

Sorry to hear you are having problems getting previews working as well as they used to.Best next step will be to file a feedback with diagnostics. If you can include a sample project where the issue reproduces then that is extremely helpful.

We will need the diagnostics Xcode Previews generates in order to make sure we understand the error the previews system is encountering.

If you are having issues with macOS, catalyst or on-device iOS previews then download and install the logging profile for your device. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift Attach the sysdiagnose to the radar as well as the diagnostics using the instructions below.

Then when you get an error in Xcode Previews, an error banner appears in the canvas (if there is no banner you can introduce a syntax error in your file to get the banner to show up. Make sure to highlight in the bug report that the syntax error was introduced purely to get at the diagnostics option)

  1. Click the "Diagnostics" button in that banner
  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)
Xcode Previews no longer update after changes to outside files
 
 
Q