代码:
vDSP_ctoz(UnsafePointer<DSPComplex>(stream), 2, &output, 1, UInt(bufferSizePOT / 2))
曾经在Swift 2.3中正常工作。现在我收到错误: 'init'不可用:使用'withMemoryRebound(to:capacity:_)临时查看内存...
“stream”是函数的参数:
func FFT(stream : UnsafeMutablePointer<Float>, size: UInt)
我猜错误信息可能会产生误导。有什么想法吗?
答案 0 :(得分:2)
似乎您需要一个基本的 UnsafePointer转换。
UnsafePointer转换
...
Unsafe[Mutable]Pointer<Pointee> { func withMemoryRebound<T>(to: T.Type, capacity count: Int, _ body: (Unsafe[Mutable]Pointer<T>) throws -> ()) rethrows }
通常,当您要将aPointer
类型的UnsafeMutablePointer<T>
转换为anotherPointer
的{{1}}时,您需要编写如下内容:
UnsafeMutablePointer<U>
在你的情况下,你可以这样写:
(假设aPointer.withMemoryRebound(to: U.self, capacity: capacity) { //<- You need `capacity` counted in `U`
anotherPointer in //<-this becomes `UnsafeMutablePointer<U>`
//...use `anotherPointer` inside the closure
//...
//Do NOT take `anotherPointer` out of this closure
}
为bufferSizePOT
。)
Int