1

I have a C pointer array from which I want to get the data in Swift. However, I need to get the data with a specific stride/stepsize and without a for loop to keep it efficient.

To get all the data I would do this:

let dataStrided = Array(UnsafeBufferPointer(start: dataPtr, count: arraySize))

But I don’t know how to obtain the unstrided data. I would think of using the Swift function stride, but the following (of course) doesn’t work:

let dataUnstrided = dataStrided[0.stride(to: arraySize-stepSize, by: stepSize)]

Would there be an efficient method to do this and avoiding a for loop?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Gerard
  • 349
  • 2
  • 16

0 Answers0