Reputation: 10169
I'm wondering if anyone got SwiftUI preview to work with a local image asset when using Swift Package Manager.
I'm not doing anything fancy. I have an asset catalog with a few images and my view looks like
public var body: some View {
Image("star_5")
.resizable()
.scaledToFit()
}
When I create an Xcode project that depends on this swift package, I can reference the previews defined there and SwiftUI shows them correctly.
Upvotes: 8
Views: 5091
Reputation: 119118
When you are inside a package, you need to pass in the bundle
, because it is the main
by default and there is no main
in a module.
So you need to use .module
as the bundle:
Image("star_5", bundle: .module)
.module
is an auto-generated resource. You don't need to manually write it!
If you faced this error:
Type 'Bundle' has no member 'module'
Follow this instruction to make it automatically build for your package
Upvotes: 16