Reputation: 939
I created a new SwiftUI project but the default code will not load in the live preview window. I get the following error every time: "Cannot preview in this file - Update failed". I am running Xcode 11.4 on Catalina 10.15.4
Image of the error in Xcode
Image of the diagnostics report
Here is a list of the things that I have tried so far:
1) Restarted Xcode and my computer
2) Cleaned the build folder of the project
3) Deleted the build folder and reran the project
4) Changed the simulator device (I've tried Generic iOS device, iPhone 11, 11 pro max, etc.)
5) Changed the project location to desktop
Any help would be much appreciated!
Upvotes: 9
Views: 5901
Reputation: 566
For me, I tried all the above and the solution was when I updated xcode to the latest version
Upvotes: 0
Reputation: 1196
It should be a lot of different problem. One of them if the "Build configuration" is Release then there should go -Onone error. You should change Release to Debug in the scheme.
Upvotes: 0
Reputation: 1725
Below steps worked for me.
SymbolCache.noindex
directory under Derived DataModuleCache.noindex
directory under Derived Data/Users/$(whoami)/Library/Developer/Xcode/UserData/Previews/
and delete everythingUpvotes: 0
Reputation: 12884
Do 2 steps:
/Users/me.myself/Library/Developer/Xcode/UserData/Previews
run
killall -9 com.apple.CoreSimulator.CoreSimulatorService
Restart Xcode
Upvotes: 4
Reputation: 410
I had a similar issue, but in my case diagnostics showed: RemoteHumanReadableError
My fix was to quit Xcode (close window and quit from menu or use CMD+Q).
Delete contents of:
/Users/$(whoami)/Library/Developer/Xcode/DerivedData/
With something like this:
rm -rf /Users/$(whoami)/Library/Developer/Xcode/DerivedData/*
NOTE: System may ask you for confirmation, so you have to answer y and tap enter (always use rm -rf with caution!).
Then start Xcode again and open project - it took little longer to load but worked fine without issue.
I just hope this helps solving OP issue as well as other simillar issues with SwiftUI preview stupid errors not related to code.
Upvotes: 0