在 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) ^
我现在需要将函数中的指针声明指定为可选吗?