Swift raw pointer to 2D Array

136 Views Asked by At

I have a pointer (buffer.contents() in code below) of type UnsafeMutableRawPointer which is a buffer of length N and holds 16 bit unsigned integers. I want to view this as a 2D array of size K x L (where K*L = N) of 16 bit unsigned integers. How do I convert this to a 2D array so that I can either print it as 2D array or better, see the contents in debugger window? This is what I did and using this pointer I can iterate over members one by one, but I cannot visualize the entire array in one shot.

let pointer = unsafeBitCast(buffer.contents(), to: UnsafeMutablePointer<UInt16>.self)
0

There are 0 best solutions below