I have a kmp module and I want to include some ima...
# ios
s
I have a kmp module and I want to include some images (.jpg) to load. I've been trying to add a
resources
directory that has the images in the commonMain and iosMain source sets and access the file uri. I added
val iosMain by getting { resources.srcDirs("src/iosMain/resources") }
in my gradle script, and in the ios sources, I was trying
NSBundle.mainBundle.pathForResource(imageName, "jpg")
but it's not find the image. I've also tried to add the images to the assets in xcode without luck but I may not have added them correctly. what's the best way to get a uri to a packaged image in a kmp module?
https://github.com/icerockdev/moko-resources is this what people use mainly for this? I know there's compose multiplatform resources but my module isn't using compose
not really impressed with moko.
f
NSBundle.mainBundle.pathForResource
means you try to get a ressource from the app, not the shared library
mainBundle
=
App itself
if you want to get some ressouces stored in a framework, you can’t use mainBundle. you need to access of the containe/bundle.
Copy code
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.example.App.ExampleFramework"];
Storing image inside the
xcassets
, can be access with UIImage(named)