When you create a new Xcode project in Xcode 13.2.1, you may face an error "Cannot preview in this file - Unexpected error occurred" or other similar error messages in the iOS swiftUI simulator preview feature. To resolve the error, try the following:
- Clicking on the "Diagnostics" button on the failed preview pane;
- Copy the ".pcm" file path. It looks like something similar to "/var/folders/aa/xxxxxxxxxxxxxxxxxxxxxxx/C/clang/ModuleCache/12345ABCDE/MyTest-XXXXXXXXXXXXXX.pcm"
- Run the following command to remove the .pcm file in the Terminal app (replace the path using the specific path you copied from the Diagnostics log obtained in the step above:
rm -rf /var/folders/aa/xxxxxxxxxxxxxxxxxxxxxxx/C/clang/ModuleCache/12345ABCDE/MyTest-XXXXXXXXXXXXXX.pcm