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

Is that an AI-generated answer? I have already mentioned that putting the project in a directory different from a “special” directory such as Documents works. I've posted my message to help people who may encounter the same issue, as it took me some time to figure it out.

What is confusing here is that Xcode has full disk access, yet a project in Documents raises a permission error. Maybe there is some other process that is invoked by preview and needs to be granted access to the Documents folder (or any other “special” folder where the project is located)?

Not AI, but just someone who missed that part of your post. I'm glad you've already found a workaround.

I can't speak to what a real fix for this would look like, but your theories sound reasonable and I'll make sure to pass those along to the relevant teams!

Thanks for reporting and using Previews!

I did another test on two different machines seemingly configured in the same way (macOS 26.4.1, Xcode 26.5), and got divergent results. These are the steps I've taken in each case:

  1. In System Preferences > Privacy & Security, remove Xcode from Full Disk Access and Files & Folders.
  2. Reboot.
  3. Open a project under the Documents folder. The user is prompted to grant Xcode access to the Documents folder. If access is denied, Xcode correctly reports that it doesn't have permissions to open the project (Xcode can still create new projects inside Documents, but I assume that this is expected behavior).
  4. In System Preferences > Privacy & Security > Files & Folder, grant Xcode access to the Documents folder.
  5. Restart Xcode and reopen the same project. The project can now be opened.

At this point, in one machine the preview shows up correctly, but in the other machine I get the “Failed to launch” error I've originally posted, and I need to apply one of the workarounds I've originally mentioned (move the project folder or toggle automatic refresh) to be able to see the previews.

So, I cannot reproduce the issue consistently: there is something else going on in one of my machines, but I don't know how to debug it further.


PS: Glad to know that the interaction is with humans making genuine mistakes! If you ever implement bots in this forum, I hope that they will clearly marked as such. My apologies to the engineers if my reply sounded harsh.

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