Hi, I have a file config.json in library/commonMai...
# multiplatform
b
Hi, I have a file config.json in library/commonMain/resources folder, How can I read it from iOS? I already try but it doesn’t work
Copy code
NSBundle.allBundles.filterIsInstance<NSBundle>().forEach { bundle ->

    val path = bundle.pathForResource("config", "json")

    if (path != null) {
        return NSString.stringWithContentsOfFile(
			path = path,
			encoding = NSUTF8StringEncoding,
			error = null
        ) as String? ?: throw IllegalStateException("Failed to read file")
    }
}
It seems that the file wasn’t copied into iOS bundle. I’m not using https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-multiplatform-resources.html because I don’t use Compose Multiplatform in the app Please help
f
Look after moko resources, it works great
b
It’s a small project and I don’t want to add a dependency, is there a “native” solution?
f
Add the resources yourself inside your Xcode project
b
that works for me, however, it’s a library and we don’t want to ship both the library and the file separately
t
You should be able to put it in a ByteArray, https://youtrack.jetbrains.com/issue/KT-39194 I guess you could generate it at build time using kotlinpoet to avoid a copy
f
Generate a base64 String of the binary file could also work
b
Thanks guys, moving file content to Kotlin source file is definitively a solution, but it may occupy memory unnecessarily. It seems there wasn’t an easy way to share Kotlin’s resources in iOS bundle.