The documentation here <Github> says: `Moko-resour...
# moko
m
The documentation here Github says:
Moko-resources has out of box implementation function for read text files from common code - readText()
But when I try to access
readText()
I can't find it am I missing something ?
a
sorry, in common code readText is not available. readText created in androidMain and iosMain - this function have different api. but if you have compose multiplatform - you can read text - https://github.com/icerockdev/moko-resources/blob/2c484808c928a13ab4d0523b82db3b5a[…]nMain/kotlin/dev/icerock/moko/resources/compose/FileResource.kt
m
I need to read the text in a non-composable function in the shared module I did it without compose resource with:
Copy code
val jsonString = Res.readBytes("files/articles.json").decodeToString()
but compose resources doesn't include the resources into the XCframework
a
write expect/actual function in this case. for android you should find way how to get Context to read file
m
I did it like this
Copy code
// commonMain
expect object FileReader {
    fun readText(file: FileResource): String
}

// androidMain
actual object FileReader {

    lateinit var context: Context

    actual fun readText(file: FileResource): String {
        return file.readText(context)
    }
}

// iOSMain
actual object FileReader {
    actual fun readText(file: FileResource): String {
        return file.readText()
    }
}
👍 1
in
Application
class I added
Copy code
FileReader.context = this
to onCreate 🫠