views:

59

answers:

1

This is my error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance

I have no idea why this is happening. Both the array (which is NSMutableArray) and the object being added are definitely not nil, and the @property for the array is straight up (nonatomic, retain).

Can anyone help?

A: 

Chances are the array is not a NSMutableArray - a NSArray is not mutable, that is, you cannot add objects to it.

I know you said it is - but if you do

NSMutableArray* someArray = [NSArray array];

you get a NSArray, not a NSMutableArray. I've done it.

Adam Eberbach
Sorry, one thing I forgot to mention in the question; I can always add one object, the second one crashes it. Always, exactly like that.
Dyldo42
You need to post more code. Does the array go out of scope between additions? Are you using code like "myArray = [NSMutableArray array]" or "self.myArray = [NSMutableArray array]"? If the former, you must use self. for the retain to take effect.
Adam Eberbach
My problem ended up being that I needed that, goddamn, mutableCopy, not copy. Cheers for the help.
Dyldo42