How do we clear out contents in NSMutableData

2019-03-14 08:12发布

How do we clear an NSMutableData without using release and then re-alloc/init again to be used again? I was looking at resetBytesInRange to be set at zero but I am unsure of this. Anyone can help?

2条回答
SAY GOODBYE
2楼-- · 2019-03-14 08:46

Swift version of the setting all the bytes to zero:

data.resetBytes(in: NSRange(location:0, length:data.length))
查看更多
SAY GOODBYE
3楼-- · 2019-03-14 08:52

If you want an empty buffer:

[data setLength:0];

If you want to keep its size but set all the bytes to zero:

[data resetBytesInRange:NSMakeRange(0, [data length])];
查看更多
登录 后发表回答