如何作为字节添加到NSMutableData

时间:2015-12-15 14:33:09

标签: swift nsmutabledata

我将浮点数附加到NSMutable以获取大量浮点数的字节流。

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

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

如何从该流中恢复数组?

更新

感谢迈克。 我按照建议做了。

// 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]));

0 个答案:

没有答案