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 官网代码很 ...
随机推荐
- MFC之sqlite
引用头文件和将生成的SQLite.dll加载到项目中 #include "sqlite3.h" 1.动态加载sqlite //***********************数据库动 ...
- easyui改变tab标题
截图: 代码: //更改tab的标题 var tab = $('#microAppVersionTabs').tabs('getTab',0);// 取得第一个tab $('#microAppVe ...
- zabbix-3.4.10系列
第1节 zabbix体系架构图:
- 测试Linux下tcp最大连接数限制
现在做服务器开发不加上高并发根本没脸出门,所以为了以后吹水被别人怼“天天提高并发,你自己实现的最高并发是多少”的时候能义正言辞的怼回去,趁着元旦在家没事决定自己写个demo搞一搞. 这个测试主要是想搞 ...
- Apache无法正常启动(配置多个监听端口)
Apache监测多个端口配置: 1.conf->extra->httpd-vhosts.conf 检查配置项是否写错 2.http.conf listen端口是否监听正确 3.环境变量中 ...
- [leetcode]380. Insert Delete GetRandom O(1)常数时间插入删除取随机值
Design a data structure that supports all following operations in average O(1) time. insert(val): In ...
- eclipse装了springboot插件后yml文件没有自动提示问题
选择打开方式:spring yaml
- autoMapper dotnetcore webapi 自动添加映射 abp
在ef的xxxxApplicationModule的Initialize方法中,已经添加了自动映射的配置,如下图: 写的很明白了,我们只需要写一个类继承Profile就可以了.如下图所示: 这样就可以 ...
- windows下mysql安装(zip包方式)
1.安装地址 https://dev.mysql.com/downloads/mysql/ 2. 解压MySQL压缩包 发现并没有my-default.ini 配置文件主要的作用是设置编码字符集.安装 ...
- Fabric的权限管理:Attribute-Based Access Control
之前稍微了解过Client Identity Chaincode Library,这几天正好开始实际应用. 虽然了解过,还是发现了不少之前理解的不足,也踩了不少坑. 先列出官方介绍: https:// ...