BD Wild BD Wild - 14 days ago 5
iOS Question

Can't pass AudioQueueRef inout parameter to AudioQueueNewOutput in Swift

Here is my code:

var queue: AudioQueueRef
error = AudioQueueNewOutput(&dataFormat,
AQOutputCallback,
&player,
nil,
nil,
0,
&queue) // This gives me an error


I get an error associated with the
queue
variable: "Cannot pass immutable value as inout argument: implicit conversion from 'AudioQueueRef' to 'AudioQueueRef?' requires a temporary".
AudioQueueNewOutput
requires that parameter to be of type
UnsafeMutablePointer<AudioQueueRef?>
. I don't know how to implement that conversion.

Any ideas on how to fix this? Thanks.

Answer

As it says that AudioQueueRef must be inout parameter means the same variable will change it's value anytime to new or old. So, you must define it as an Optional like below:

var queue: AudioQueueRef? 

var error = AudioQueueNewOutput(&dataFormat, 
AQOutputCallback, 
&player, 
nil, 
nil, 
0, 
&queue)

Let me know, if you still face any issues.

Comments