Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear out contents in NSMutableData

I am new to Swift and iOS Development. How do we clear an NSMutableData without using release and then re-alloc/init again to be used again?

I have tried resetBytesInRange() but that replaces the contents by zero.

I tried data.length = 0, but there is garbage data at the end after appending.

data.setData(nil) gives an error.

I read this question but it doesn't solve my problem on swift.

Please help.

like image 548
saurabh Avatar asked Aug 31 '25 18:08

saurabh


1 Answers

Try using setData() with NSData():

mytableData.setData(NSData())
like image 153
Eimantas Avatar answered Sep 02 '25 07:09

Eimantas