7

I made a widget using new and shiny WidgetKit. It looks good and working as expected. Then I put all its logic into separate framework to share constant values between extension and main app as well as to provide a unit-testable target. And after introducing a framework SwiftUI previews stopped working. I'm getting error: Cannot preview in this file - Could not find host for previews. It seems that WidgetPreviewContext is not working. I'm wondering why. Could it be because I'm on macOS Catalina 10.15.6?

Artem Kirillov
  • 1,132
  • 10
  • 25
  • 1
    What are the "Diagnostics"? – Micha C. Oct 12 '20 at 08:25
  • 1
    If it's the same error as me then diagnostics are as below. Did you have any luck @Artem ? ```"UnableToFindPreviewHostError: Could not find host for previews Could not find a host (app, extension, framework) given the open files and active `PreviewProvider` types. Make sure the open files and `PreviewProvider` types are target in the active scheme."``` – NeilInglis Oct 15 '20 at 12:39
  • @MichaC. Sorry for delay. Yeah, Neillnglis mentioned the same diagnostics as I have. So far, I haven't got any further with it. – Artem Kirillov Oct 16 '20 at 11:42
  • Are you directly preview your YourWidget under preview? Instead preview the widget's main view. Also preview doesn't work on macOS, works only for iOS – user1046037 Nov 25 '22 at 21:54

1 Answers1

-1

I fixed this because I guess some of the files I had open in the workspace wasn't part of the same target?

Anyways I fixed this error by closing all files I had open in Xcode except the SwiftUI Code.