问题
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?
回答1:
This should do the trick:
[myArray removeAllObjects];
回答2:
In Swift 3:
yourArry.removeAllObjects()
回答3:
// In Swift
arrayName.removeAllObjects()
回答4:
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];}
来源:https://stackoverflow.com/questions/3857920/how-do-i-remove-all-objects-from-an-nsmutablearray