我有这个功能

func arrayForPointer<T>(_ pointer: UnsafePointer<T>, count: Int) -> [T] {
let buffer = UnsafeBufferPointer<T>(start: pointer, count: count)
return Array(buffer)
}

还有这个电话
let arrayComplex = self.arrayForPointer(&output, count: 4)

我想枚举到arrayComplex并将实数部分提取到一个正则数组中,比如
var arrayReal: [Float] = []

for item in arrayComplex {
  let myFloat = item.realp  \\ get the real part of item
  arrayReal.append(myFloat)
}

线
let myFloat = item.realp  \\ get the real part of item

不正确。
item是一个UnsafeMutablePointer<Float>
看在上帝的份上,我该怎么做?
谢谢。
=======================
这是output
var A = [Float](repeating:0, count:samples/2);
var B = [Float](repeating:0, count:samples/2)
var output = DSPSplitComplex(realp: &A, imagp: &B)

最佳答案

试试这个。
修复func调用:

let arrayComplex = arrayForPointer(output.realp, count: 4)

然后在循环中修复这一行:
let myFloat = item  \\ get the real part of item

关于swift - 将UnsafeMutablePointer的实部提取为Float并将其存储在数组中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54641266/

10-10 19:12