Xcode Preview on Device failed

Hi, when I try to preview any Xcode SwiftUI project on my external device (e.g. on iPhone X, iPad Pro) I always get the message:

'Cannot preview in this file - Failed to update preview'.

The App 'Xcode Previews' on the iPhone starts up but the screen stays white. This happens with all Xcode projects, even the simple 'Hello World' template. Preview in the Xcode canvas area works fine, also the simulator. The app can also be installed and runs fine on the iPhone, just the 'Preview on Device does not work. I have tried several Xcode versions (12.3, 12.4 and 12.5 beta), all with the same issue. Have seen the issue reported by others, but no solution yet. Pressing on 'Diagnostics' shows the following report:

RemoteHumanReadableError: Failed to update preview.

Error encountered when sending 'display' message to agent.

==================================

|  RemoteHumanReadableError

|  

|  LoadingError: failed to load library at path "/private/var/mobile/Containers/Data/Application/4F3B9E10-7F01-49EA-B755-3C810ABE9A12//tmp/2FCDE6E3-4B4B-49E4-92F4-1C5156089C36-ContentView.2.preview-thunk.dylib": Optional(dlopen(/private/var/mobile/Containers/Data/Application/4F3B9E10-7F01-49EA-B755-3C810ABE9A12/tmp/2FCDE6E3-4B4B-49E4-92F4-1C5156089C36-ContentView.2.preview-thunk.dylib, 2): no suitable image found.  Did find:

|  /private/var/mobile/Containers/Data/Application/4F3B9E10-7F01-49EA-B755-3C810ABE9A12/tmp/2FCDE6E3-4B4B-49E4-92F4-1C5156089C36-ContentView.2.preview-thunk.dylib: code signature invalid for '/private/var/mobile/Containers/Data/Application/4F3B9E10-7F01-49EA-B755-3C810ABE9A12/tmp/2FCDE6E3-4B4B-49E4-92F4-1C5156089C36-ContentView.2.preview-thunk.dylib'

|  )
Sorry to hear you are having problems getting previews working on-device. The best next step will be to file a feedback with diagnostics. 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 (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)

Thanks for the feedback, I have created a bug report in the Feedback assistant and attached the corresponding diagnostics report as outlined above, ticket number is FB9007700. Please have a look at this.

I am experiencing the same problem 2 years after this was originally raised by the OP.

I've tried both my iPhone 14 Pro and iPad Air 4, running iOS/iPadOS 16.2, connected to MacBook Pro M1 Pro running Ventura 13.2.1 and Xcode Version 14.2.

I can build and run on those devices successfully, but Xcode Preview on device does not work.

We believe the original issue reported here has been resolved several releases ago. If you you are still seeing issues please file a new feedback using the most current Xcode release. Please make sure to include 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 bug report 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

  1. Click the "Diagnostics" button in that banner (or if the banner is missing you can use the menu: Editor > Canvas > 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)
Xcode Preview on Device failed
 
 
Q