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 开发者_C百科crashes.
Can anyone tell me the best way to do this with a code example if possible?
This should do the trick:
[myArray removeAllObjects];
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];
In Swift 3:
yourArry.removeAllObjects()
// In Swift
arrayName.removeAllObjects()
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];}
精彩评论