How do we clear out contents in NSMutableData

本小妞迷上赌 提交于 2020-01-12 02:30:53

问题


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?


回答1:


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



回答2:


Swift version of the setting all the bytes to zero:

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


来源:https://stackoverflow.com/questions/1890778/how-do-we-clear-out-contents-in-nsmutabledata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!