参数类型是Constant Pointer

也就是 UnsafePointer<Type>

可以传入的类型:

  1. UnsafePointer<Type>/UnsafeMutablePointer<Type>/AutoreleasingUnsafeMutablePointer<Type>
  2. String。如果TypeUInt8Int8
  3. 可变类型的 Typein-out 类型。
  4. [Type] 类型,被当作指向第一个元素的地址

例子如下:

func takesAPointer(_ p: UnsafePointer<Float>) {
// ...
} var x: Float = 0.0
takesAPointer(&x)
takesAPointer([1.0, 2.0, 3.0])

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.

参数类型是 Mutable Pointer

UnsafeMutablePointer<Type>
可以传入的类型:

  1. UnsafeMutablePointer<Type>
  2. 可变类型的 Typein-out 类型。
  3. [Type] 类型,必须是可变类型。

例子:

func takesAMutablePointer(_ p: UnsafeMutablePointer<Float>) {
// ...
} var x: Float = 0.0
//是var类型
var a: [Float] = [1.0, 2.0, 3.0]
takesAMutablePointer(&x)
takesAMutablePointer(&a)

参数类型是Autoreleasing Pointer

AutoreleasingUnsafeMutablePointer<Type>
可以传入:

  1. AutoreleasingUnsafeMutablePointer
  2. 可变类型的 Typein-out 类型。

参数类型是 Function Pointer

可以传入的类型有:

  1. top-level Swift function
  2. a closure literal
  3. a closure declared with the @convention(c) attribute
  4. nil

例子:

func customCopyDescription(_ p: UnsafeRawPointer?) -> Unmanaged<CFString>? {
// return an Unmanaged<CFString>? value
} var callbacks = CFArrayCallBacks(
version: 0,
retain: nil,
release: nil,
copyDescription: customCopyDescription,
equal: { (p1, p2) -> DarwinBoolean in
// return Bool value
}
)
var mutableArray = CFArrayCreateMutable(nil, 0, &callbacks)

Calling Functions With Pointer Parameters的更多相关文章

  1. Swift 函数的定义与调用(Defining and Calling Functions)

    当你定义一个函数时,你能够定义一个或多个有名字和类型的值.作为函数的输入(称为參数.parameters).也能够定义某种类型的值作为函数运行结束的输出(称为返回类型). 每一个函数有个函数名,用来描 ...

  2. (转) Functions

    Functions Functions allow to structure programs in segments of code to perform individual tasks. In ...

  3. 【Swift】 - 函数(Functions)总结 - 比较 与 C# 的异同

    1.0 函数的定义与调用( Defining and Calling Functions ) 习惯了C#了语法,看到下面的这样定义输入参数实在感到非常别扭,func 有点 Javascript的感觉, ...

  4. 'this' pointer in C++

    The 'this' pointer is passed as a hidden argument to all nonstatic member function calls and is avai ...

  5. Python Data Science Toolbox Part 1 Learning 1 - User-defined functions

    User-defined functions from:https://campus.datacamp.com/courses/python-data-science-toolbox-part-1/w ...

  6. [翻译] Using Custom Functions in a Report 在报表中使用自己义函数

    Using Custom Functions in a Report  在报表中使用自己义函数   FastReport has a large number of built-in standard ...

  7. In-Out Parameters inout keyword

    You write an in-out parameter by placing the inout keyword right before a parameter’s type. An in-ou ...

  8. windows消息机制详解(转载)

    消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...

  9. Openfire Strophe开发中文乱码问题

    网站上有很多Openfire Web方案,之前想用Smack 但是jar包支持客户端版本的,还有JDK版本问题  一直没调试成功  估计成功的方法只能拜读源码进行修改了. SparkWeb 官网代码很 ...

随机推荐

  1. Scrollview包裹布局问题。

    输入框获取焦点,键盘弹出,背景图片上移: https://blog.csdn.net/wljian1/article/details/79962802 android:scrollbarThumbVe ...

  2. js监控鼠标滚动事件

    //滚动动画 windowAddMouseWheel(); function windowAddMouseWheel() { var scrollFunc = function (e) { e = e ...

  3. 651. 4 Keys Keyboard复制粘贴获得的最大长度

    [抄题]: Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on scre ...

  4. autoMapper dotnetcore webapi 自动添加映射 abp

    在ef的xxxxApplicationModule的Initialize方法中,已经添加了自动映射的配置,如下图: 写的很明白了,我们只需要写一个类继承Profile就可以了.如下图所示: 这样就可以 ...

  5. RFC

    一.简介   二.常用 1)TLSv1.2 Protocol https://tools.ietf.org/html/rfc5246

  6. docker容器的使用

    Docker客户端 docker客户端非常简单,我们可以直接输入docker命令来查看到Docker客户端的所有命令选项. runoob@ docker 可以通过命令docker command -- ...

  7. How to configure Samba Server share on Debian 9 Stretch Linux

    Lubos Rendek Debian 13 June 2017 Contents 1. Objective 2. Operating System and Software Versions 3.  ...

  8. centOS redis的安装及配置

    1.下载redis的安装包 wget http://download.redis.io/releases/redis-4.0.2.tar.gz 我一般wget的文件都是在一个download的文件夹里 ...

  9. 1.3eigen中数组类和系数的运算

    1.3数组类和系数的运算 与矩阵类只适用与线性代数运算相反,数组类提供通用的数组类,能不利用线性代数的知识来对系数进行操作,比如对每个系数加上一个常数,或者乘上两个数组的系数. 1.数组类型 跟矩阵类 ...

  10. 数据库-mysql语句-查

    复习: 列类型: 数值类型:   20   '20' tinyint / smallint / int / bigint float / double / decimal(m,d) bool (TRU ...