objective c - removeObject in ios -
this question has answer here:
- removing object nsmutablearray 5 answers
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
Post a Comment