Recently I have noticed that Previews have stopped working in an app I am working on. I am using the latest Xcode and Catalina (Beta 7). If I add a new View - TestView to my project, its preview fails. This is with no modifications i.e. the default "Hello World" View. The diagnostics say 'TestView' is not a member type of 'MyProject'. Any ideas on how to fix this?
If I create a new project, the Previews work fine.
The project runs fine on an actual device or simulator.
The full diagnostics message is: 'TestView' is not a member type of 'MyProject'
failedToBuildDylib: /Users/nigelhamilton/Library/Developer/Xcode/DerivedData/MyProject-bgufjjqbmfuwcaahjswocfzmwsgx/Build/Intermediates.noindex/Previews/MyProject/Intermediates.noindex/MyProject.build/Debug-iphonesimulator/MyProject.build/Objects-normal/x86_64/TestView.2.preview-thunk.swift:23:32: error: 'TestView' is not a member type of 'MyProject' typealias TestView = MyProject.TestView ~~~~~~~~~ ^ /Users/nigelhamilton/Library/Developer/Xcode/DerivedData/MyProject-bgufjjqbmfuwcaahjswocfzmwsgx/Build/Intermediates.noindex/Previews/MyProject/Intermediates.noindex/MyProject.build/Debug-iphonesimulator/MyProject.build/Objects-normal/x86_64/TestView.2.preview-thunk.swift:16:6: error: replaced accessor for 'body' could not be found @_dynamicReplacement(for: body) private var __preview__body: some View { ^
I am currently deleting code from my project (or at least a duplicate of the project) to see if it eventually starts to show the preview again. I have had two goes at this, and it has eventually worked, but with most of the code deleted. So I am trying to narrow down where the problem might be.
I think I have solved this. I had made what probably sounds like a stupid mistake. The project uses CoreData and I had given one of the Entities the same name as the project. Whilst that might sound crazy, the project would build and run (simulator or device) without a problem. It was just the preview that was getting confused. I have renamed the Entity and at least some of the Views can be previewed, including the TestView mentioned above. There are still a couple of Views not previewing correctly, but I think that is due to another issue.