Tuesday, November 8, 2016

Passing an Array of Strings From Swift to C

Ole Begemann:

The type checker allows you to pass a String value to an UnsafePointer<Int8> or UnsafePointer<UInt8> parameter. When you do that, the compiler will transparently create a buffer containing the UTF-8-encoded, null-terminated string, and pass a pointer to that buffer to the function.


However, some C functions take an array of strings (a char ** or char *[]), and there is no built-in support in Swift for passing a [String] to a char ** parameter.


The full type of the strlen function as imported by Swift looks like this[…]

1 Comment RSS · Twitter

[…] Passing an Array of Strings From Swift to C, Swift 3.0 Unsafe World, Swift and C […]

Leave a Comment