<div dir="ltr"><span class="im" style="font-size:13px">>> Can I define similar for my Swift classes ?<br><br></span>>No. What would be your use case?<br><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">I also could have my Swift object with several members, but when send to native part would like to send address exactly one of members.</span></div><div><span style="font-size:13px">Something like this:</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">// Swift part</span></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">class</span> ABlock {</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(187,44,162)">var</span> channels = <span style="color:rgb(39,42,216)">2</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(187,44,162)">var</span> samplerate = <span style="color:rgb(39,42,216)">44100</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">        </span></span><span style="color:rgb(187,44,162)">var</span><span style="color:rgb(0,0,0)"> buffer : </span>UnsafeMutablePointer<span style="color:rgb(0,0,0)"><</span>Int16<span style="color:rgb(0,0,0)">></span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(187,44,162)">init</span>() {</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">                </span></span><span style="color:rgb(79,129,135)">buffer</span><span style="color:rgb(0,0,0)"> = </span>UnsafeMutablePointer<span style="color:rgb(0,0,0)"><</span>Int16<span style="color:rgb(0,0,0)">>.</span><span style="color:rgb(61,29,129)">alloc</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(39,42,216)">2048</span><span style="color:rgb(0,0,0)">)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span>}</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">        </span></span>deinit<span style="color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">                </span></span><span style="color:rgb(79,129,135)">buffer</span><span style="color:rgb(0,0,0)">.</span>dealloc<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(39,42,216)">2048</span><span style="color:rgb(0,0,0)">)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span>}</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">}</p></div><div><br></div><div>var block = ABlock</div><div>generate(block) <- here I would like to send address of ABlock.buffer to native part</div><div><br></div><div>// C part</div><div>void generate(int16_t *buf) {</div><div>...</div><div>}</div><div><span style="font-size:13px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 11, 2016 at 4:54 PM, Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Re-adding swift-users back.<br>
<span class=""><br>
On Wed, Feb 10, 2016 at 11:49 PM, Sergey Kuratov <<a href="mailto:ksubox.swift@gmail.com">ksubox.swift@gmail.com</a>> wrote:<br>
> Thank you, Dmitri!<br>
><br>
> I wonder how this automatic transformation to unsafe pointer happens (I<br>
> guess elements buffer has some offset from array object memory) ?<br>
<br>
</span>The compiler knows how to extract the pointer from the array, and how<br>
to extend its lifetime to ensure it is not deallocated before the C<br>
function returns.<br>
<span class=""><br>
> Can I define similar for my Swift classes ?<br>
<br>
</span>No. What would be your usecase?<br>
<div class="HOEnZb"><div class="h5"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
</div></div></blockquote></div><br></div>