开发者

How do we clear out contents in NSMutableData

开发者 https://www.devze.com 2022-12-14 00:05 出处:网络
开发者_Go百科How do we clear an NSMutableData without using release and then re-alloc/init again to be used again?

开发者_Go百科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?


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


Swift version of the setting all the bytes to zero:

data.resetBytes(in: NSRange(location:0, length:data.length))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号