Passing a preallocated char* buffer to a c function

Viewed 545

I have a function in c that receives a preallocated string and fills it with data - I'd like to call this function from swift. I've found many examples on how to pass strings from swift to c, but I found none showing c functions that write the data on a preallocated string.

The c function:

int GetData(char *dataJson, int maxSize);

On the swift side, this code compiles, but I can't find how to preallocate dataBuffer

let dataBuffer = UnsafePointer<UInt8>
GetData(dataBuffer, 2048)

Is there a way to do so in Swift?

2 Answers
Related