vDSP_zvmags Swift 4.2 error

Prior swift versions: Swift 4.0, one was able to pass an inout [Float] array into the vDSP_zvmags functions however, since updating to Swift 4.2 Xcode 10 is complaining about using the [Float].

self.magnitudes = [Float](repeating: 0.0, count: self.halfSize)

vDSP_zvmags(&(self.complexBuffer!), 1, &self.magnitudes!, 1, UInt(self.halfSize))


The error is on the self.magnitudes parameter:


Cannot convert value of type '[Float]' to expected argument type 'Float'


Running this code on Xcode 9.4.1 - Swift 4.1 works, but Xcode 10.1 - Swift 4.2 has an error.


Could someone please help shed some light on this?

Replies

Can you post more details about your code? Specifically, I’d like to see the declarations of each of the properties referenced by the example you posted.

I tried reproducing this here in my office and couldn’t. Specifically:

  1. I used Xcode 10.1 to create a new test project from the iOS > Single View App template.

  2. I added the following code to

    ViewController.swift
    .
    var halfSize: Int = 0
    var magnitudes: [Float]? = nil
    var complexBuffer: DSPSplitComplex? = nil
    
    
    func test() {
        self.magnitudes = [Float](repeating: 0.0, count: self.halfSize)
        vDSP_zvmags(&(self.complexBuffer!), 1, &self.magnitudes!, 1, UInt(self.halfSize))
    }

    .

It compiled just fine, so clearly I’m missing some key point about your code.

ps If you format you code as code, using the

<>
icon, it makes it easier to read.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"