Workarounds for Xcode previews errors: Cannot preview in this file - Failed to Launch

I have started to have issues with SwiftUI previews of iOS apps with projects under the Documents folder. I have experimented that in Xcode 26.4 and I am still seeing it in 26.5. The error is:

Cannot preview in this file. Failed to launch xyz.abc.TestApp

Looking at the diagnostics, Xcode gets a permission denied error when trying to open

/Users/me/Documents/path/to/TestApp/DerivedData/TestApp/Build/Intermediates.noindex/TestApp.build/Debug-iphonesimulator/TestApp.build/Objects-normal/arm64/ContentView.1.preview-thunk-launch.o

Error details below. Note that I have set DerivedData folders relative to the projects' roots. Additional information:

  • I get errors on freshly created iOS projects, just trying to preview the default ContentView.
  • Xcode has full disk access set in System Preferences > Privacy & Security.
  • I have cleaned build folders, deleted the simulators, Xcode itself, cleared various caches, restarted and reinstalled Xcode to no avail.
  • Checking Editor > Canvas > Use Legacy Previews Execution did not fix it either.
  • Apps run fine in Simulator.
  • System info: macOS 26.4.1, Xcode 26.5 (17F42), MacBook Pro M1 and Mac Studio M2 Max.

I have found two ways to fix the problem while keeping DerivedData relative to the project's root:

  1. create the project in some other “unprotected” directory (/Users/me/Developer in my case), or
  2. uncheck Editor > Canvas > Automatically Refresh Canvas.

Either way makes previews work again.

Possibly related:

Excerpt from diagnostics:

    |  |  [Remote] JITError
    |  |  
    |  |  ==================================
    |  |  
    |  |  |  [Remote] CouldNotLoadInputObjectFile: Could not load object file during preview: /Users/me/Documents/TestApp/DerivedData/TestApp/Build/Intermediates.noindex/TestApp.build/Debug-iphonesimulator/TestApp.build/Objects-normal/arm64/ContentView.1.preview-thunk-launch.o
    |  |  |  
    |  |  |  path: /Users/me/Documents/TestApp/DerivedData/TestApp/Build/Intermediates.noindex/TestApp.build/Debug-iphonesimulator/TestApp.build/Objects-normal/arm64/ContentView.1.preview-thunk-launch.o
    |  |  |  
    |  |  |  ==================================
    |  |  |  
    |  |  |  |  [Remote] XOJITError
    |  |  |  |  
    |  |  |  |  XOJITError: '/Users/me/Documents/TestApp/DerivedData/TestApp/Build/Intermediates.noindex/TestApp.build/Debug-iphonesimulator/TestApp.build/Objects-normal/arm64/ContentView.1.preview-thunk-launch.o': Operation not permitted

Hi,

Sorry to hear you are having problems getting previews working. We believe you are hitting a known issue with having source and/or DerivedData be in one of the "special" file locations of macOS which includes Downloads, Desktop, Documents (and in some cases external Volumes). Could you try moving the source and DerivedData out of those locations and see if that resolves the issue for you?

If it does not, the best next step will be to file a feedback with diagnostics so we can take a look.

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

Install the logging profile using instructions available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift On your mac running Xcode, and on your physical preview device (if you are using one).

Install the logging profile using the following instructions on your mac running Xcode; and if you are using one, your physical preview device (iOS or visionOS): https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift

Then when you reproduce the problem in Xcode:

  1. Either (a) an error banner will appear, click the "Diagnostics" button in that banner; or (b) if you're not seeing an error but you still want to provide diagnostics you can get the same diagnostics window by going under the Editor menu in the menu bar, then selecting the Canvas submenu, then selecting "Diagnostics".
  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)
  4. Generate a sysdiagnose on your mac and any on-device preview devices, and attach those too
Workarounds for Xcode previews errors: Cannot preview in this file - Failed to Launch
 
 
Q