Problem with Xcode

Hello Chris
I have been having problems with Xcode over the past 1 month. I cannot get my preview and sometimes the simulator working. I have Macbook Air M1 2020 with OS 11.6 and Xcode 13.2.1. When I try to build a simple “Hello World” program it says Failed to build ContentView. swift.
Other errors in the task bar are:

  1. Waiting to connect and unlock device
  2. Copying cache files from the device
  3. Fetching debug symbols for Iphone
  4. Waiting to connect and unlock the device
    I am at my wits end as none of the programs built over the few months are working.
    Can you help please. Thanks Jaime

If you are using your real device as a simulator then points 1, 2, 3 and 4 are normal.

For issues with your Preview can you provide a screenshot of your Xcode window which illustrates the fact that your Preview is not working. Show your code and your left Navigator panel at the same time as in this example below.

Hello Chris,
Please find the screen shot as requested.
Thanks Jaime

The next thing to do is reset the simulator.

From the simulator menu select Device > Erase All Contents and Settings. After it has been erased it will restart. This will set the simulator back to its original state which means that any App loaded on the Simulator will be removed.

Thanks Chris. I have reinstalled Xcode and the simulator now works. In the simulator menu the Device > Erase All Contents and Settings is greyed out and cannot be selected.
The preview still does not work and gives the error “Failed to build ContentView swift” .

The abridged error message is CompileDylibError: Failed to build ContentView.swift

Compiling failed: file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/RuntimeStubs.h’ has been modified since the module file ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/1GS1IUNF6IO19/SwiftShims-2TTN5UXQBRCCQ.pcm’ was built: mtime changed

:0: error: file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/RuntimeStubs.h’ has been modified since the module file ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/1GS1IUNF6IO19/SwiftShims-2TTN5UXQBRCCQ.pcm’ was built: mtime changed

:0: note: please rebuild precompiled header ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/1GS1IUNF6IO19/SwiftShims-2TTN5UXQBRCCQ.pcm’

:1:9: note: in file included from :1:

#import “LibcOverlayShims.h”

Hope this helps in resolving this issue. Thanks Jaime

Ah yes, I have seen that error before where it will not build the Preview.

What I had to do is close the project in Xcode and in Finder, navigate to the folder in which the SwiftShims-2TTN5UXQBRCCQ.pcm file is contained and put it in the trash.

In your case the path is:
/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/1GS1IUNF6IO19/

Scroll down the list until you find SwiftShims-2TTN5UXQBRCCQ.pcm and drag it to the Trash and then re-open the project.

Let me know if that solves the Preview issue.

Sorry Chris, I do not know know how to navigate to the folder in Finder. My foray with Apple began only with my desire to learn Swift with Code with Chris less than a year ago. I need you further guidance how to locate the folder and the file.
Thanks, Jaime

OK simple way to do that is from the Finder menu, select Go then Go to Folder.

In the dialog box that comes up, paste in the path in the previous reply from me.

To make the files easier to identify, change your Folder view to List view by selecting the icon as indicated in the attached screenshot

Select List view so that the filenames are longer.

Scroll down the list till you find the file named:

SwiftShims-2TTN5UXQBRCCQ.pcm

and delete it.

Reopen the project in Xcode and see if the Preview now works. Xcode will re-create that file and this time its contents should be correct.

Hello Chris, Thanks, the preview now works only for the trial program “Hello World” . However it does not work with other earlier programs. The simulator however works perfectly for all programs. How can I fix this? I created another trail program and the preview works. The diagnostic message of the earlier programs are the identical.
Thanks Jaime
.

The problem is that for every earlier project that you have, where you are experiencing problems with the Preview, each has it’s own SwiftShims file that you may need to remove.

If you do then you need to navigate down the Folder tree unique to each of those projects and delete that file. It’s a hassle to say the least but hopefully there are not too many that you have to deal with.

Hello Chris, this solution works only for new projects. For earlier projects even if I delete the said file the preview still does not show. There seems to be something more embedded in the view which is not allowing the preview to show. I am attaching the Diagnostic message hoping that you could find the cause. I have reloaded X code a coupIe of times to see if that was the cause. I find it hard to work without the preview. Thank you again and sorry for being such a pain.

Diagnostic Message
file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/RuntimeStubs.h’ has been modified since the module file ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm’ was built: mtime changed


CompileDylibError: Failed to build ContentView.swift

Compiling failed: file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/RuntimeStubs.h’ has been modified since the module file ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm’ was built: mtime changed

:0: error: file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/RuntimeStubs.h’ has been modified since the module file ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm’ was built: mtime changed
:0: note: please rebuild precompiled header ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm’
:1:9: note: in file included from :1:
#import “LibcOverlayShims.h”
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/LibcOverlayShims.h:21:2: error: file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/RuntimeStubs.h’ has been modified since the module file ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm’ was built: mtime changed
#include “Visibility.h”
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/LibcOverlayShims.h:21:2: note: please rebuild precompiled header ‘/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm’
#include “Visibility.h”
^
:0: error: missing required module ‘SwiftOverlayShims’

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

| BuildInvocationError
|
| /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -F /Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator -enforce-exclusivity=checked -DDEBUG -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -target arm64-apple-ios14.0-simulator -Xfrontend -serialize-debugging-options -enable-testing -swift-version 5 -I “/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Products/Debug-iphonesimulator” -F “/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Products/Debug-iphonesimulator” -c -j8 -serialize-diagnostics -Xcc “-I/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/swift-overrides.hmap” -Xcc -iquote -Xcc “/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/M2L4 Challenge-generated-files.hmap” -Xcc “-I/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/M2L4 Challenge-own-target-headers.hmap” -Xcc “-I/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/M2L4 Challenge-all-target-headers.hmap” -Xcc -iquote -Xcc “/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/M2L4 Challenge-project-headers.hmap” -Xcc “-I/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Products/Debug-iphonesimulator/include” -Xcc “-I/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/DerivedSources-normal/arm64” -Xcc “-I/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/DerivedSources/arm64” -Xcc “-I/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/DerivedSources” -Xcc -DDEBUG=1 -working-directory “/Users/jaimefernandes/Desktop/M2L4 Challenge” “/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/Objects-normal/arm64/ContentView.1.preview-thunk.swift” -o “/Users/jaimefernandes/Library/Developer/Xcode/DerivedData/M2L4_Challenge-glqjcvahswldgedcdfjjqqdsdutc/Build/Intermediates.noindex/Previews/M2L4 Challenge/Intermediates.noindex/M2L4 Challenge.build/Debug-iphonesimulator/M2L4 Challenge.build/Objects-normal/arm64/ContentView.1.preview-thunk.o” -module-name M2L4_Challenge_PreviewReplacement_ContentView_1 -Onone -Xfrontend -disable-modules-validate-system-headers -gline-tables-only

It’s the same issue.

Close the project in Xcode.

In Finder, use the Go > Go to Folder option from the Menu and paste in the path:

/var/folders/9l/8qbb82213nlct0fd7rmg1vgm0000gn/C/clang/ModuleCache/108X1IN8WGNX1/

Scroll down till you find the file

SwiftShims-2TTN5UXQBRCCQ.pcm

and delete it.

It’s the same filename in each project that encounters this issue. The path is slightly different in that the last Folder will be different. ie, where this project has 108X1IN8WGNX1 as the last folder name, it will be different for another project.

Thanks Chris, you are a genius. Removing another file has cleared the issues with the preview for most of the other projects. It has also given me an understanding of reading diagnostics. Great help!
Jaime

1 Like