Inter-operability of Swift arrays with C?

前端 未结 4 1925
终归单人心
终归单人心 2021-02-02 09:46

How can one pass or copy the data in a C array, such as

float foo[1024];

, between C and Swift functions that use fixed size arrays, such as d

4条回答
  •  无人及你
    2021-02-02 10:21

    The withUnsafePointerToElements() method was removed, now you can use the withUnsafeBufferPointer() instead, and use the baseAddress method in the block to achieve the point

    let array: Array = [10.0, 50.0, 40.0]
    array.withUnsafeBufferPointer { (cArray: UnsafePointer) -> () in
        cArray.baseAddress
    }
    

提交回复
热议问题