Quick form of the question for those who know Rust: is there a Swift 5 equivalent of
std::ffi::CString that can own a String and turn it into a
char* like into_raw and later free/drop it using something like from_raw?
I have a C API that I am consuming in Swift. I have to supply a callback function, which I am supplying as a closure argument, and that closure must return a null-terminated string as a
const char *—in Swift this is typed as
Clearly somebody has to be responsible for that memory and when it will be freed. In this case I would like to say that it is heap-allocated, and Swift is responsible for it and it will keep that
const char * alive until the C interface finishes with it and calls some sort of
What is the least painful way to allocate some memory in Swift initialised with a UTF-8 string, provide a
const char * to C, then free it later when instructed?