Calling Functions With Pointer Parameters

参数类型是Constant Pointer
也就是 UnsafePointer<Type>
可以传入的类型:
UnsafePointer<Type>/UnsafeMutablePointer<Type>/AutoreleasingUnsafeMutablePointer<Type>String。如果Type是UInt8或Int8。- 可变类型的
Type的in-out类型。 [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>
可以传入的类型:
UnsafeMutablePointer<Type>- 可变类型的
Type的in-out类型。 [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>
可以传入:
- AutoreleasingUnsafeMutablePointer
- 可变类型的
Type的in-out类型。
参数类型是 Function Pointer
可以传入的类型有:
- top-level Swift function
- a closure literal
- a closure declared with the @convention(c) attribute
- 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的更多相关文章
- Swift 函数的定义与调用(Defining and Calling Functions)
当你定义一个函数时,你能够定义一个或多个有名字和类型的值.作为函数的输入(称为參数.parameters).也能够定义某种类型的值作为函数运行结束的输出(称为返回类型). 每一个函数有个函数名,用来描 ...
- (转) Functions
Functions Functions allow to structure programs in segments of code to perform individual tasks. In ...
- 【Swift】 - 函数(Functions)总结 - 比较 与 C# 的异同
1.0 函数的定义与调用( Defining and Calling Functions ) 习惯了C#了语法,看到下面的这样定义输入参数实在感到非常别扭,func 有点 Javascript的感觉, ...
- 'this' pointer in C++
The 'this' pointer is passed as a hidden argument to all nonstatic member function calls and is avai ...
- 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 ...
- [翻译] Using Custom Functions in a Report 在报表中使用自己义函数
Using Custom Functions in a Report 在报表中使用自己义函数 FastReport has a large number of built-in standard ...
- 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 ...
- windows消息机制详解(转载)
消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...
- Openfire Strophe开发中文乱码问题
网站上有很多Openfire Web方案,之前想用Smack 但是jar包支持客户端版本的,还有JDK版本问题 一直没调试成功 估计成功的方法只能拜读源码进行修改了. SparkWeb 官网代码很 ...
随机推荐
- SpringCloud详解
来源于纯洁的微笑 http://www.ityouknow.com/spring-cloud.html
- python中使用Opencv进行车牌号检测——2018.10.24
初学Python.Opencv,想用它做个实例解决车牌号检测. 车牌号检测需要分为四个部分:1.车辆图像获取.2.车牌定位.3.车牌字符分割和4.车牌字符识别 在百度查到了车牌识别部分车牌定位和车牌字 ...
- const命令声明变量应注意的几点
对于复合类型的变量,变量名不指向数据,而是指向数据所在的地址.const命令只是保证变量名指向的地址不变,并不保证该地址的数据不变,所以将一个对象声明为常量必须非常小心. const person = ...
- C++ 实现 split 操作
理由:由于 C++ 标准库里面没有字符分割函数 split ,这可太不方便了,我们利用 STL 来实现自己的 split 函数: 原型:vector<string> split(const ...
- ubuntu输入法
一直都是使用搜狗的,但是感觉一直都不兼容.经常输入一串文字导致输入法崩溃 比如 ‘外显’waixian就崩了. 而且会出现fcitx 100%cpu占用的情况 pkill fcitx &&am ...
- 对于PHP面试知识点的小结
基础篇 了解大部分数组处理函数 字符串处理函数(区别 mb_ 系列函数) & 引用,结合案例分析 == 与 === 区别 isset 与 empty 区别 全部魔术函数理解 static.$t ...
- zeromq学习记录(六)C语言示例
考虑到官方的示例c语言是最多的 官方未使用C++语言演示的例子就使用VC编译C语言例子 记录在此 /************************************************** ...
- django by example 第四章 dashboard处html无法渲染问题
描述: 实现django by example 代码时,第四章 dashboard处html无法渲染问题. 此时报错,NoReverseMatch at /account/login/, Error ...
- 差分模版题(需理解才明白)AT2442 フェーン現象 (Foehn Phenomena)
https://www.luogu.org/problemnew/show/AT2442 #include <bits/stdc++.h> #define read read() #def ...
- python模块:time
# encoding: utf-8 # module time # from (built-in) # by generator 1.145 """ This modul ...