Bin*_*ian 4 pointers ampersand swift
在Swift中,&符号&
用于inout
参数.喜欢
var值= 3
func inoutfunc(inout onlyPara:Int){
onlyPara ++
}
inoutfunc(&value)//值现在为4
这看起来不像onlyPara
是一个指针,也许它是在函数内部使用它时立即得到解引用.
只有帕拉指针?
当我不需要IntPointer
类型时,为什么框架方法使用NSErrorPointer
类型?因为现有的Objective-C代码无法改变方法?
但是为什么Swift转换&error
为NSErrorPointer
自动编码?
var errorPtr:NSErrorPointer =&error
当我有一个NSErrorPointer
.我如何取消引用它?
var error:NSError =*errorPtr //将无效
也许有人可以开导我.仅使用Swift很容易.我认为问题是&
swift和Objective-C之间的一小部分知识(作为运算符的地址)
我建议你阅读使用Swift with Cocoa和Objective-C指南的指针部分:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/DOC/UID/TP40014216-CH8-XID_16
指针部分底部有一个表,它解释了类指针如何桥接到Swift指针类型.基于此,NSError指针应该是AutoreleasingUnsafePointer<NSError>
.搜索NSErrorPointer的标题会产生以下结果:
typealias NSErrorPointer = AutoreleasingUnsafePointer<NSError?>
Run Code Online (Sandbox Code Playgroud)
为什么额外的?
后NSError
?我想这是因为NSError也可以nil
.
希望能帮助到你!
归档时间: |
|
查看次数: |
4400 次 |
最近记录: |