https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

JoakimForslund

04/01/2019, 12:20 PM
Is there a way in kotlin multiplatform to include a imagefile in the resources that later will be loadable with i.e:
image = UIImage.imageNamed("image/$file.png");
from iOS target? My current idea is using base64 and storing it common code but it would be pretty sweet if the resources-folder could be used in my static library
1
r

r4zzz4k

04/01/2019, 12:57 PM
There is a thing called
ImmutableBlob
, which is particularly useful for accessing non-modifiable binary data, but the only way to create them is corresponding factory function: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native/immutable-blob-of.html AFAIK, there's nothing ready-made which can take your resources and represent them as blobs, but writing Gradle task converting files into Kotlin source code calling
immutableBlobOf
should be fairly straightforward.
g

gildor

04/01/2019, 1:03 PM
I would prefer some MPP library + support from Gradle side, that would provide API to access resources and bundle src/res files to output format of target platform (Jar resources, bundled binaries on native, maybe inline to base64 on JS etc)
r

r4zzz4k

04/01/2019, 1:04 PM
That's obviously much more desirable, I'm just suggesting a workaround.
g

gildor

04/01/2019, 1:10 PM
yeah, sure 👍 Just shared my wishes 🙈
j

JoakimForslund

04/01/2019, 2:27 PM
If the automatic generation also handled moving the files to a image folder inside the xcode project, I think it would be an acceptable solution
For kotlin generate a MainBundle.nameOfTheFile that contains the blob/base64 data