我想从iPhone连接Alexa,因为我使用的是一个在
Github上用swift 2.2编写的样本
所以我需要将其转换为Swift 3.0
从xcode迁移到Swift 3.0到xift完成后几乎解决了所有错误,现在剩下的唯一错误与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 :(仅用于param缓冲区)
let audioBufferQueue = Array<AudioQueueBufferRef>(repeating: nil, count: numberBuffers)
并且在swift 2.2中它工作正常,但在swift 3.0中它显示错误
/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
我搜索了谷歌和stackoverflow但没有找到解决方案.我尝试重写和谷歌的东西,但没有解决.
谁能告诉我如何解决这个问题?
最佳答案 在Swift 3中,使用AudioQueueBufferRef?而不是AudioQueueBufferRef:
let buffers = Array<AudioQueueBufferRef?>(repeating: nil, count: numberBuffers)
// and allocate each buffer
for i in 0 ..< buffers.count {
AudioQueueAllocateBuffer(inQueue!, bufferSize, &buffers[i])
}