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