4

I want to connect Alexa from iPhone, for that I am using a sample which is written in swift 2.2 on Github

So I need to convert that into Swift 3.0

Migrated from Swift 2.2 to Swift 3.0 from xcode is done which resolved almost all the errors, now the only error which is left is related to AudioQueueBufferRef

Swift 2.2:

self.recorderState = RecorderState(
            setupComplete: false,
            dataFormat: AudioStreamBasicDescription(),
            queue: UnsafeMutablePointer<AudioQueueRef>.alloc(1),
            buffers: Array<AudioQueueBufferRef>(count: numberBuffers, repeatedValue: nil),
            recordFile: AudioFileID(),
            bufferByteSize: 0,
            currentPacket: 0,
            isRunning: false,
            recordPacket: 0,
            errorHandler: nil)

Swift 3.0: (just for param buffers)

let audioBufferQueue = Array<AudioQueueBufferRef>(repeating: nil, count: numberBuffers)

and in swift 2.2 it is working fine but in swift 3.0 it is showing an error

/Users/macbookpro/Downloads/iOS-Alexa-master copy/iOS Alexa/AVS/SimplePCMRecorder.swift:28:32: Expression type 'Array' (aka 'Array>') is ambiguous without more context

SimplePCMRecorder of Swift 2.2 on Github

I have searched on google and stackoverflow but didn't find the solution. I tried rewriting and google things but no resolved.

Can anyone please tell me how to resolve this issue?

Muhammad Raza
  • 952
  • 7
  • 24

1 Answers1

1

In Swift 3, use AudioQueueBufferRef? instead of AudioQueueBufferRef:

let buffers = Array<AudioQueueBufferRef?>(repeating: nil, count: numberBuffers)

// and allocate each buffer
for i in 0 ..< buffers.count {
  AudioQueueAllocateBuffer(inQueue!, bufferSize, &buffers[i])
}
Jean Regisser
  • 6,636
  • 4
  • 32
  • 32