Reputation: 5616
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?
Upvotes: 14
Views: 20602
Reputation: 880
1.Create instance of NSMutableArray in .h file
@property (strong, nonatomic) NSMutableArray* arrayEmployee;
2.@synthesize in .m file
@synthesize arrayEmployee;
3.Remove all objects from an NSMutableArray
[self.arrayEmployee removeAllObjects];
Upvotes: 2
Reputation: 11
in case [YourArray removeAllObjects]; doesn't work.
Then do it manually as below:
int c = (int)[YourArray count]-1;
for (int l = 0; l <= c; l++) {[YourArray removeObjectAtIndex:0];}
Upvotes: -2
Reputation: 55583
This should do the trick:
[myArray removeAllObjects];
Upvotes: 35