Reputation: 535
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
Tried on Xcode 13.4.1, 14.0.1, 14.1_beta_3 but error is same.
Upvotes: 4
Views: 910
Reputation: 535
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"]
),
]
...
Upvotes: 2