Search code examples
iosswiftcore-audioaudiotoolbox

AudioQueueNewOutput with AudioQueueRef? always unwrapping nil


I have this snippet of code

var queue: AudioQueueRef?
try SCoreAudioError.check(status: AudioQueueNewOutput(&dataFormat!, myAQOutputCallback, &player, nil, nil, 0, &queue),"`AudioQueueNewOutput` had an error")

Which, for some reason, the AudioQueueRef? is unwrapping its value before being sent

fatal error: unexpectedly found nil while unwrapping an Optional value

as far as I know, I need an empty reference AudioQueueRef? in the AudioQueueNewOutput function, and that reference is going to be filled with data aren't I right?

If I'm right, then why is this happening?


Solution

  • I think your AudioQueueRef is fine, and instead dataFormat is nil.