Is there example, how to read text file on iOS (e....
# kotlin-native
k
Is there example, how to read text file on iOS (e.g. if i have some kind of filepath)?
k
you will need a multiplatform library for file handling, or you will need to use the iOS platform APIs. https://github.com/AAkira/Kotlin-Multiplatform-Libraries
👍 1
k
We pass in a lambda from swift on app start
Type is
(filePrefix: String, fileType: String) -> String?
Copy code
func loadAsset(filePrefix:String, fileType:String) -> String?{
        do{
            let bundleFile = Bundle.main.path(forResource: filePrefix, ofType: fileType)
            return try String(contentsOfFile: bundleFile!)
        } catch {
            return nil
        }
    }
There are places where coding something in swift is much easier than trying to sort out the interop equivalent (although it can make unit tests more difficult)