[英]In Xcode 8 (Swift 3) what does UnsafeMutablePointer<_> mean?
The following code: 以下代码:
var mutableDataP = UnsafeMutablePointer<Int16>(audioBuffer.mData)
let stereoSampleArray = UnsafeMutableBufferPointer(
start: mutableDataP,
count: nBytesInBuffer/sizeof(Int16) // Int16 audio samples
)
gives the following error: 给出以下错误:
Cannot convert value of type 'UnsafeMutablePointer' to expected argument type 'UnsafeMutablePointer<_>'
无法将'UnsafeMutablePointer'类型的值转换为预期的参数类型'UnsafeMutablePointer <_>'
What is an UnsafeMutablePointer<__> and how do I cast to it? 什么是UnsafeMutablePointer <__>以及如何投射它? I tried all the casting variations I could think of and got un-understandable diagnostics for each and I've run out of ideas.
我尝试了所有我能想到的铸造变体,并且每个都有不可理解的诊断方法,而且我已经没有想法了。 I find the documentation on the various UnsafeMutablePointer types unhelpful, and no mention at all of '<_>'.
我发现各种UnsafeMutablePointer类型的文档都没有用,并且根本没有提到'<_>'。
Try this change: 试试这个改变:
let stereoSampleArray = withUnsafeMutablePointer(to: &audioBuffer.mData){
return UnsafeMutableBufferPointer(
start: $0,
count: nBytesInBuffer/MemoryLayout<Int16>.size // Int16 audio samples
)
}
Where audioBuffer.mData
is a var
其中
audioBuffer.mData
是var
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.