开发者

Resetting NSMutableArray

开发者 https://www.devze.com 2022-12-09 23:09 出处:网络
What i开发者_开发问答s the best a quickest way to reset an NSMutableArray?-[NSMutableArray removeAllObjects] doesn\'t work for you?removeAllObjectsremoveAllObjectsif assuming by \'reset\', you mean yo

What i开发者_开发问答s the best a quickest way to reset an NSMutableArray?


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


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.

0

精彩评论

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