0

I am appending floats to a NSMutable to get a bytestream of a lot of floats.

for var i=0 ;i < 10000 ;i++{

   let myfloat=floatarray[i];
   testdata.appendBytes(&myfloat, length: sizeof(Float));
}

How do I get the array back from that stream ?

UPDATE

Thanks to Mike. I did as suggested.

// Have to cast the pointer to the right size
        let pointer = UnsafePointer<Float>(testdata.bytes)
        let count = testdata.length / sizeof(Float);

        // Get our buffer pointer and make an array out of it
        let buffer = UnsafeBufferPointer<Float>(start:pointer, count:count)
        let array = [Float](buffer)


        print(String(array[0]));
mcfly soft
  • 11,289
  • 26
  • 98
  • 202

0 Answers0