【发布时间】:2017-02-20 03:14:25
【问题描述】:
在 Swift 2.2 中,我能够将 nil 作为有效参数传递给需要 UnsafePointer<UInt8> 的函数。在 Swift 3 中,我不能再这样做了:
func myFuncThatTakesAPointer(buffer: UnsafePointer<UInt8>, length: Int) { /** **/ }
myFuncThatTakesAPointer(buffer: nil, length: 0)
Playground execution failed: error: Xcode8Playground-iOS.playground:62:33: error: nil is not compatible with expected argument type 'UnsafePointer<UInt8>' myFuncThatTakesAPointer(buffer: nil, length: 0) ^
我现在需要在我的函数中将指针声明指定为可选吗?
【问题讨论】:
-
请查看this。
标签: swift swift3 unsafe-pointers