<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Hi all-</p>
<p dir="auto">So I've been working on this for hours and I'm just stuck. In C I'd write something like:</p>
<p dir="auto">const char* a_string_array[] = {"aloha", "world", "from beautiful Waikiki Beach"};<br>
haveFun(a_string_array);</p>
<p dir="auto">and haveFun is:</p>
<p dir="auto">void haveFun(const char** data) {<br>
printf("%s\n", data[0]);<br>
printf("%s\n", data[1]);<br>
printf("%s\n", data[2]);<br>
}</p>
<p dir="auto">So I'm trying to do something similar in Swift 3-REL (working in Linux) and the best I've been able to come up with is:</p>
<p dir="auto">func haveSwiftFun(data: Optional<UnsafeMutablePointer<Optional<UnsafePointer<Int8>>>>, count:UInt32) {<br>
for _ in 0...count {<br>
if let parm = params?.pointee! {<br>
let tempBuf = String(cString: (UnsafePointer<Int8>(parm)!))<br>
print(tempBuf)<br>
}<br>
}<br>
}</p>
<p dir="auto">But I'm not actually iterating through the array, I'm just getting the first element count times. </p>
<p dir="auto">I've been all over the usual places on the web (SO, Apple Docs, etc.), and have cobbled together something like:</p>
<p dir="auto">let buffer = UnsafeBufferPointer(start:(params?.pointee!)!, count:count)<br>
let anArray = Array(buffer)</p>
<p dir="auto">which gives me an [Int8], but I can't figure out how to get the actual char array from the anArray elements, with the hope of turning each element into its own String.</p>
<p dir="auto">I'm feeling I've run off the rails here and am hoping somebody might have some info on how to properly deal with working with a const char** in Swift 3. I'm sure/not sure it'll be an obvious 'ah ha!' moment, but that moment seems very very far away. :(</p>
<p dir="auto">Thanks for any help,</p>
<p dir="auto">Ron </p>
</div>
</div>
</body>
</html>