I was not able to run any previews in my framework, and I received the following message: 'XCPreviewAgent crashed due to fatalError...'.
I managed to fix the issue myself, and since it wasn't easy, I decided to share my investigation and solution in an answer, hoping it will help other developers.
My preview crashed because it could not access my font resources. I am working on a framework, and it seems that for frameworks, the resources are not copied into the app package of the preview.
I verified this by examining the contents of the preview: /Users/YOUR_NAME/Library/Developer/Xcode/UserData/Previews/Simulator Devices/DEVICE_UUID/data/Containers/Bundle/Application/APPLICATION_UUID/APPLICATION_NAME.app.
(Make sure to replace "YOUR_NAME," "DEVICE_UUID," "APPLICATION_UUID," and "APPLICATION_NAME" with the actual names or UUIDs relevant to your specific situation.)
Now right-click on the app and select Show Package Contents.
For previews that work correctly, the name of the associated app is used, and you will see all the resources in the package. However, my framework was not using the framework name. Instead, it was named XCPreviewAgent.app and did not contain any resources from my framework.
As of now (Xcode 16.0 and Xcode 16.1), the fix is to use Legacy Preview Execution.
In the menu, select Editor > Canvas > Legacy Preview Execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With