天天看點

Calling Functions With Pointer Parameters

Calling Functions With Pointer Parameters

也就是 <code>UnsafePointer&lt;Type&gt;</code>

可以傳入的類型:

<code>UnsafePointer&lt;Type&gt;</code>/<code>UnsafeMutablePointer&lt;Type&gt;</code>/<code>AutoreleasingUnsafeMutablePointer&lt;Type&gt;</code>

<code>String</code>。如果<code>Type</code> 是 <code>UInt8</code> 或 <code>Int8</code>。

可變類型的 <code>Type</code> 的 <code>in-out</code> 類型。

<code>[Type]</code> 類型,被當作指向第一個元素的位址

例子如下:

The pointer you pass to the function is only guaranteed to be valid for the duration of the function call. Do not persist the pointer and access it after the function has returned.

即<code>UnsafeMutablePointer&lt;Type&gt;</code>

<code>UnsafeMutablePointer&lt;Type&gt;</code>

<code>[Type]</code> 類型,必須是可變類型。

例子:

即<code>AutoreleasingUnsafeMutablePointer&lt;Type&gt;</code>

可以傳入:

AutoreleasingUnsafeMutablePointer

可以傳入的類型有:

top-level Swift function

a closure literal

a closure declared with the @convention(c) attribute

nil

繼續閱讀