I am not familiar with a way to convert a two dimensional array from C to an array of Strings which I can use in Swift. As far as I know there is no quick and easy way to do this in Swift.
This is the header of my C function:
char **getAllFilePaths(const char path []);
I tried the following:
//Get the pointer of the String array
if var ptr = getAllFilePaths(a) {
//Check if the current String is null
while let s = ptr.pointee {
//Copy the String into an array
a_paths.append(String(cString: s)) //<- Crash: Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
//Go to the next adress
ptr += 1
}
print(a_paths)
}
(I have this code from Martin R: https://stackoverflow.com/a/38422783/10269733. Unfortunately it doesn't work anymore in Swift 4.2)
I am searching for a solution for this problem all day, therefore I am open for any kinds of creative ideas!
EDIT:
This code works perfectly
char paths [FILES_MAX][PATH_MAX];
static size_t i = 0;
char **getAllFilePaths(const char path []){
PrintFile(path);
size_t j;
for(j = 0; j < i; j++){
printf("%s\n", paths[j]);
}
return paths;
}