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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -