0

我有这个功能

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)
4

1 回答 1

1

尝试这个。

修复你的 func 调用:

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

然后在你的循环中修复这一行:

let myFloat = item  \\ get the real part of item
于 2019-02-12T01:19:57.007 回答