Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove all objects from an NSMutableArray?

I need to remove all objects from an NSMutableArray. I can't seem to do this by enumerating as the code crashes.

Can anyone tell me the best way to do this with a code example if possible?

like image 991
GuybrushThreepwood Avatar asked Oct 04 '10 18:10

GuybrushThreepwood


People also ask

What is difference between NSArray and NSMutableArray?

NSArray creates static arrays, and NSMutableArray creates dynamic arrays.

What is NSMutableArray?

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray .


2 Answers

This should do the trick:

[myArray removeAllObjects];
like image 159
Richard J. Ross III Avatar answered Oct 21 '22 14:10

Richard J. Ross III


In Swift 3:

yourArry.removeAllObjects()
like image 25
Renjithnath Ramachandran Avatar answered Oct 21 '22 15:10

Renjithnath Ramachandran