3

I am using a SPM package and added one simple DashboardView inside the package as below:

import SwiftUI

struct DashboardView: View {
    var body: some View {
        Text("Hello World")
    }
}

struct DashboardView_Previews: PreviewProvider {
    static var previews: some View {
        DashboardView()
    }
}

When I try to preview DashboardView, I get error:

Cannot preview in this file

Could not find host for previews

Preview Error Detail

Tried on Xcode 13.4.1, 14.0.1, 14.1_beta_3 but error is same.

Enes F.
  • 406
  • 6
  • 17
  • I had this when the Widget file's target membership was both the main app as well as the WidgetExtension. Unchecking the main target fixed it in that case. – Arjan Apr 18 '23 at 10:53

1 Answers1

1

In Package.swift file of my SPM Package, I just removed the line below which defines library type as static and error is gone.

let package = Package(
...

products: [
    // Products define the executables and libraries a package produces, and make them visible to other packages.
    .library(
        name: "MyKit",
        type: .static, // <- This line removed
        targets: ["MyKit"]
    ),
]

...
Enes F.
  • 406
  • 6
  • 17