标签:com 可变 元素 creat var access pre 必须 ring
?
也就是 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.
即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)
即AutoreleasingUnsafeMutablePointer<Type>
可以传入:
Type
的 in-out
类型。可以传入的类型有:
例子:
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
标签:com 可变 元素 creat var access pre 必须 ring
原文地址:https://www.cnblogs.com/huahuahu/p/Calling-Functions-With-Pointer-Parameters.html