Cannot preview in this file - unexpected error occurred

When I run my project called ‘iCube’ with the swiftUI simulator, the build succeeds, but a few seconds later on the top of the simulator this error comes up: ‘Cannot preview in this file - unexpected error occurred.’ When I create a new project called ‘TestApp’ or ‘HelloWorld’ it works fine, but if I create a new project called ‘iCube’ (the same name as the old project) then the simulator does not work again. Any ideas what I can do? I don’t want to have to change the name of my app.

@TorenCoder
What happens if you delete the old project from your simulator first before re-running it?

[quote=“Chris_Parker, post:2, topic:2394”]
What happens if you delete the old project from your simulator first before re-running it?
[/quote

I just tried that but it still isn’t working. Any other ideas?

@TorenCoder
If you are familiar with the DerivedData folder, which is where the Xcode build data is located, you could try deleting the corresponding project data from that folder.

To do that you should first close Xcode.

In Finder select Go > Go to Folder and type in
~/Library/Developer/Xcode/DerivedData/
Locate the folder associated with your project - in your case it will be iCube… - and delete it.

Open Xcode and create a new project of that name and see if that now works.

If that has no effect then the only other suggestion I can think of is to reset that simulator you are using.

From the simulator menu, select Hardware > Erase all contents and settings

Go back to Xcode and re-run the project.

If none of those suggestions work then maybe someone else has an idea.

Thanks! I will delete the DerivedData folder now.

Thanks so much after I deleted my DerivedData it worked again!