Swift access to variable length array

后端 未结 1 1681
长发绾君心
长发绾君心 2020-12-17 01:24

Core Audio has a C API that copies some data into memory you supply. In one case, I need to pass in a pointer to an AudioBufferList, which is defined as:

st         


        
相关标签:
1条回答
  • 2020-12-17 01:55

    You can create a buffer pointer that starts at the given address and has the given number of elements:

    let buffers = UnsafeBufferPointer<AudioBuffer>(start: &bufferList.memory.mBuffers,
        count: Int(bufferList.memory.mNumberBuffers))
    
    for buf in buffers {
        // ...
    }
    

    Update for Swift 3 (and later):

    let buffers = UnsafeBufferPointer<AudioBuffer>(start: &bufferList.pointee.mBuffers,
        count: Int(bufferList.pointee.mNumberBuffers))
    
    for buf in buffers {
        // ...
    }
    
    0 讨论(0)
提交回复
热议问题