<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Have you read <a href="https://developer.apple.com/library/tvos/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-ID17">https://developer.apple.com/library/tvos/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-ID17</a> ?</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 29, 2016 at 4:55 PM, James Campbell via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">​Do you know of any resources to brush up on the pointer aspect of swift ? ​</div></div><div class="gmail_extra"><span class=""><br clear="all"><div><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">







<p><b><font color="#cc0000">___________________________________</font></b></p><p><b>James⎥Head of Trolls</b></p><p><b><font color="#cc0000"><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>⎥<a href="http://supmenow.com" target="_blank">supmenow.com</a></font></b></p><p><b><font size="2">Sup</font></b></p><p><b><font size="2">Runway East
</font></b></p><p><b><font size="2">10 Finsbury Square</font></b></p><p><b><font size="2">London</font></b></p><p><b><font size="2">
EC2A 1AF </font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br></span><span class=""><div class="gmail_quote">On 29 July 2016 at 09:10, Dmitri Gribenko <span dir="ltr">&lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Fri, Jul 29, 2016 at 12:55 AM, James Campbell &lt;<a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>&gt; wrote:<br>
&gt; So this:<br>
&gt;<br>
&gt; if let data = someArrayGeneratingFunction() {<br>
&gt;   cFunction(UnsafeMutablePointer(data))<br>
&gt; }<br>
&gt;<br>
&gt; Has issues with the array passed to c getting corrupted, but this doesn&#39;t:<br>
&gt;<br>
&gt; let data = someArrayGeneratingFunction()<br>
&gt;<br>
&gt; if let data = data {<br>
&gt;   cFunction(UnsafeMutablePointer(data))<br>
&gt; }<br>
<br>
</span>Neither piece of code is guaranteed to work.  (You are just getting<br>
lucky that the second one happens to work.)  Array-to-pointer<br>
conversion only extends the lifetime of the array until the immediate<br>
function call returns.  So after UnsafeMutablePointer(data) returns,<br>
the array can be freed.<br>
<br>
Use someArrayGeneratingFunction.withUnsafeMutableBuffer { ... } instead.<br>
<div><div><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf(&quot;%d\n&quot;,i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;*/<br>
</div></div></blockquote></div><br></span></div>
<br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>