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:
Waiting to connect and unlock device
Copying cache files from the device
Fetching debug symbols for Iphone
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.
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
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.
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
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’
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