SwiftUI: Automatic Preview Updating Error "Failed to build ContentView.swift"

First select the Xcode using following command

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Then run

sudo xcodebuild -license

Hope it is helpful


I solved that problem by going to the Xcode - Preferences -> Locations and assigning the Command Line Tools to Xcode 11. Also keep in mind that it is a beta, so it is unstable.


Xcode SwiftUI Previews may occasionally fail with an error message about a modified .h file, such as “file Header.h has been modified since the module file Module.pcm was built: mtime changed.” (85938686)

Workaround: Delete the Clang module cache by running the following command in Terminal:

rm -rf "$TMPDIR/../C/clang/ModuleCache"

Then try to preview the file again.

https://developer.apple.com/documentation/Xcode-Release-Notes/xcode-13_3-release-notes


I had this problem as I was using // to comment beside my curly brackets to check I had them all in the right spot in my screen code. Xcode seems to cope with a few but once the screen gets too large and too many comments...... Now I comment on the line below and no problems!