There is no built-in method as far as I know.
You have to iterate over the returned pointer array, converting C strings to Swift Strings, until a nil pointer is found:
if var ptr = f() {
var strings: [String] = []
while let s = ptr.pointee {
strings.append(String(cString: s))
ptr += 1
}
// Now p.pointee == nil.
print(strings)
}
Remark: Swift 3 uses optional pointers for pointers that can be nil.
In your case, f() returns an implicitly unwrapped optional because
the header file is not "audited": The compiler does not know whether
the function can return NULL or not.
Using the "nullability annotations" you can provide that information
to the Swift compiler:
const char * _Nullable * _Nullable f(void);
// Imported to Swift as
public func f() -> UnsafeMutablePointer<UnsafePointer<Int8>?>?
if the function can return NULL, and
const char * _Nullable * _Nonnull f(void);
// Imported to Swift as
public func f() -> UnsafeMutablePointer<UnsafePointer<Int8>?>
if f() is guaranteed to return a non-NULL result.
For more information about the nullability annotations, see for example
Nullability and Objective-C in the Swift blog.