Reset NSMutableArray

What is the best way to reset NSMutableArray?

+6
iphone nsmutablearray
source share
4 answers

- [NSMutableArray removeAllObjects] not working for you?

+27
source share

removeAllObjects

+5
source share

removeAllObjects , if you assume 'reset', you mean you just want to clear the array.

+3
source share

If you are trying to do what I think you are trying to do in order to keep the array empty but not release it, or at least make it available the next time you need it, first you need to install a variable or property inside your class for this variable:

 NSMutableArray *mutableArray; 

Then add this code to the position where you need an empty array:

 if (!mutableArray) { mutableArray = [[NSMutableArray alloc] init]; } 

Now you can safely call

 [mutableArray removeAllObjects]; 

without fear that the array will become inaccessible after empty.

+1
source share

All Articles