Removing object from NSMutableArray

前端 未结 5 1441
栀梦
栀梦 2020-12-03 21:28

I stumbled across the following shortcut in setting up a for loop (shortcut compared to the textbook examples I have been using):

for (Item *i in items){ ...         


        
5条回答
  •  一个人的身影
    2020-12-03 21:51

    An Objective-C collection must not be modified during enumeration.

    You may use this variant to delete objects from collection:

    for (NSInteger i = items.count - 1; i >= 0 ; i--) {
       [items removeObjectAtIndex:i];
    }
    

提交回复
热议问题