Question

What is the best a quickest way to reset an NSMutableArray?

Was it helpful?

Solution

-[NSMutableArray removeAllObjects] doesn't work for you?

OTHER TIPS

removeAllObjects

removeAllObjects if assuming by 'reset', you mean you just want to empty the array.

If you are attempting to do what I think you are attempting to do, which is to keep an array empty but not release it, or at least to make it available next time it is needed then firstly you need to set a variable or a property within your class for this variable:

NSMutableArray *mutableArray;

Next add this code before the position at which you will need the empty array:

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

Now you can safely call

[mutableArray removeAllObjects];

without fear that the array will become unavailable once empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top