I’m currently developing an SDK in XCFramework format, but I’m facing issues displaying images. The sample repository can be found here.
The Example
target is the SDK and includes an Assets.xcassets
folder. Within Assets.xcassets
, there’s an image named neko.png
, which I’m trying to display in MyImage.swift
.
Here’s the relevant code snippet from MyImage.swift
:
public var body: some View {
HStack {
Image("neko")
.resizable()
.frame(width: 100, height: 100)
Image("neko", bundle: Bundle(identifier: "com.example.Example"))
.resizable()
.frame(width: 100, height: 100)
Image("neko", bundle: Bundle(for: Dummy.self))
.resizable()
.frame(width: 100, height: 100)
}
}
The ExampleApp
target is an iOS app that simulates the integration of the SDK. I’ve linked Example.framework
via "Frameworks, Libraries, and Embedded Content." In ContentView.swift
, I call MyImage()
:
var body: some View {
VStack {
MyImage()
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
}
However, when running ExampleApp
, I encounter the following error, and the image doesn’t display:
No image named 'neko' found in asset catalog for /Users/xxxxx/Library/Developer/CoreSimulator/Devices/xxxxx/data/Containers/Bundle/Application/xxxxx/ExampleApp.app
Adding neko.png
to ExampleApp
’s Assets.xcassets
resolves the issue.
It seems that I’m not passing the bundle
correctly when calling Image()
in MyImage.swift
. Additionally, when I run print(Bundle.allFrameworks)
within ExampleApp
, Example.framework
doesn’t appear to be included.
I also tried adding the .xcframework
built using xcodebuild
to "Frameworks, Libraries, and Embedded Content" instead of Example.framework
, but it didn’t resolve the issue.
If anyone has insights on how to resolve this, I’d greatly appreciate it!
Your framework is a static library, static libraries don't have their own Bundles. Set Build Settings->Linking General->Mach-O Type to Dynamic Library.