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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -