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

Davide Giuseppe Farella

04/19/2020, 6:42 PM
What is the entry point for
squareup.okio
on the shared code? The doc uses
File
which is only a jvm type
Oh, nvm, I just looked at the source code and noticed that only jvm is implemented 😅 So, what is the best way for handle files on shared code? Basically I need to write a file and read its name
a

Amanjeet Singh

04/19/2020, 6:58 PM
So, I did this recently have not tested this quite well on iOS so you might need to test it well. But what you need is to define
expect
declarations in common module and then
actual
declarations in
iosMain
and
androidMain
(jvm implementation). For eg:
Copy code
In common,
expect class FileUtils(path: String) {
    fun readFile(): String
}
In androidMain,
actual class FileUtils actual    constructor(path: String){
   fun readFile() = File(path).readText()
}
In ioS main similarly,
you can do in actual NSString.stringWithContentsOfFile(
                    rootPath,
                    NSUTF8StringEncoding,
                    null
            )
``````
d

Davide Giuseppe Farella

04/19/2020, 7:17 PM
I don't really need to read the content of the file, but write an archive (let's suppose it's a zip) to disk and read the file names into a folder
a

Amanjeet Singh

04/19/2020, 7:40 PM
yup all file dependent features are platform dependent then in this case of zip you need to create zip in JVM and ios in both
actuals
.
👍 1
d

Davide Giuseppe Farella

04/19/2020, 8:14 PM
I was hoping in a MP library
a

Amanjeet Singh

04/19/2020, 8:39 PM
Yup I also tried to find it but couldn't let me also know if you find one.
5 Views