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.
/Users/nigelhamilton/Library/Developer/Xcode
and delete DerivedData - reopen Xcode. This will not cause any data loss, but the next build might take some more time, because Xcode has to do everything again. – AdamokPreviewProvider
? All signs point (at least to me) as though the issue is there. – Newbillstruct TestView_Previews: PreviewProvider { static var previews: some View { TestView() } }
– SacrariumContentView
notTestView
. And this is why I'm asking. I'm guessing if you actually go through the pain of (a) creating a brand new project, (b) import everything you've coded and customized without changing a single thing toContentView
everything will build and run. Next, go through the pain of (a) keeping yourContentView
but - View by View - include your custom-named things while (b) building and running against all three outputs - device, simulator, Preview - you may find your issue. – NewbillTestView
toContentView
? – Newbill