参数类型是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. SpringCloud详解

    来源于纯洁的微笑 http://www.ityouknow.com/spring-cloud.html

  2. C++ 11 创建和使用 unique_ptr

    unique_ptr 不共享它的指针.它无法复制到其他 unique_ptr,无法通过值传递到函数,也无法用于需要副本的任何标准模板库 (STL) 算法.只能移动unique_ptr.这意味着,内存资 ...

  3. Deploy, Issue and Transfer Tokens

    [Deploy, Issue and Transfer Tokens] 本例使用 eosio.token 合约来尝试发行Token. 1.签出 eosio.contracts. git clone h ...

  4. Linux进程的原理及与信号的联系

    第1节 程序.进程.守护进程.僵尸进程的区别 程序.进程.守护进程.僵尸进程: 程序:c/php/java,代码文件,静态的,放在磁盘里的数据. 进程:正在内存中运行的程序,进程是动态的,会申请和使用 ...

  5. np.cumsum()函数和正则表达式的含义

  6. 微信小程序记账本进度六

    //app.jsApp({ onLaunch: function () { //调用API从本地缓存中获取数据 var logs = wx.getStorageSync('logs') || [] l ...

  7. 213. House Robber II 首尾相同的偷窃问题

    [抄题]: You are a professional robber planning to rob houses along a street. Each house has a certain ...

  8. 364. Nested List Weight Sum II 大小反向的括号加权求和

    [抄题]: Given a nested list of integers, return the sum of all integers in the list weighted by their ...

  9. 什么是XML?

    XML被设计用来传输和存储数据. HTML被设计用来显示数据. 什么是XML? XML指可扩展标记语言(EXtensible Markup Language) XML是一种标记语言,很类似HTML X ...

  10. [leetcode]94. Binary Tree Inorder Traversal二叉树中序遍历

    Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] ...