Henrik
01/28/2020, 9:32 AMval contents = "File contents"
val filename = "some.file"
val res = contents.writeToFile(filename, true, NSUTF8StringEncoding)
I have succeeded using the simpler overload without encoding end error, but the NSError*/throws
is causing me problems. How can I supply/catch that parameter from Kotlin?Artyom Degtyarev [JB]
01/29/2020, 9:15 AMNSError
in the function signature, one should allocate the object in native memory, and then pass it to the function. For example, like
memScoped {
val error = alloc<ObjCObjectVar<NSError?>>()
("SampleText" as NSString).writeToFile(
path ="/absolute/path/toWrite/text",
atomically =true,
encoding = NSUTF8StringEncoding,
error =error.ptr)
println(error.value)
}
Henrik
01/29/2020, 9:20 AMArtyom Degtyarev [JB]
01/29/2020, 9:25 AMmemScoped
block, it will be released automatically as soon as the block ends. There are other ways to work with native memory in K/N, see here(https://github.com/JetBrains/kotlin-native/blob/v1.3.60/INTEROP.md#memory-allocation) and here(https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop/-arena/index.html).Henrik
01/29/2020, 9:26 AM