Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSMutableArray removeObjectAtIndex

I'm getting the following error when removing from my NSMutableArray

-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x1cdced10
2011-07-13 00:33:14.333 MassText[1726:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x1cdced10'

However right before I remove, I print out the array and the index. Neither are nil and I have no reason to believe why this error would be happening. Any ideas?

like image 764
StanLe Avatar asked Jul 13 '11 04:07

StanLe


2 Answers

I had this problem. Mine was that I accidentally used type casting like this.

NSMutablearray * myarray = [[NSMutableArray alloc] init];
myarray =(NSMutableArray*) [mydictionary allkeys];

This will work for some time.. but if you are in a tight and large loop this tend to fail.

I changed my code to

NSMutableArray * myarray= [[NSMutablearray alloc] initWithArray:[mydictionary allKeys]];
like image 180
Martin Jacob Avatar answered Sep 29 '22 14:09

Martin Jacob


The object is an NSArray, not an NSMutableArray.

like image 33
ThomasW Avatar answered Sep 29 '22 14:09

ThomasW