How do I remove all objects from an NSMutableArray?

喜欢而已 提交于 2021-02-16 04:28:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!