天天看点

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

继续阅读