objective c - removeObject in ios -


this question has answer here:

my program has nsmutable array named "matchedcards", , have added few object in of type card, need remove objects array, , use following code it:

for (card * removecards in matchedcards)   {     [self.matchedcards removeobject:removecards];   } 

the first card-object gets removed , , after program gets crashed , can explain reason behind it, if removes first object, why starts throwing error 2nd object onwards

you can't remove elements array while fast-enumerating it.
if want remove objects do

[self.matchedcards removeallobjects]; 

if want remove elements however, remember indices in indexset , remove those

nsmutableindexset* indexestoremove = [nsmutableindexset new]; (nsuinteger index = 0; index < [self.matchedcards count]; ++index)  {     if (whatever) {         [indexestoremove addobject:index];     } }   [self.matchedcards removeobjectsatindexes:indexestoremove]; 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -