I've been having a really weird problem. I have a mutable array that is claiming to be mutable and claiming to respond to addObject:, but crashes saying that its not mutable.
Here is the code:
NSLog(@"Can add object: %d", [[MySingleton sharedInstance].myArray respondsToSelector:@selector(addObject:)]);
if([[MySingleton sharedInstance].myArray isKindOfClass:[NSMutableArray class]])[[MySingleton sharedInstance].myArray addObject:objectToAdd];
else NSLog(@"Not mutable");
Now, if I set it to mutable copy, it works.
NSLog(@"Can add object: %d", [[MySingleton sharedInstance].myArray respondsToSelector:@selector(addObject:)]);
if([[MySingleton sharedInstance].myArray isKindOfClass:[NSMutableArray class]])[[MySingleton sharedInstance].myArray.mutableCopy addObject:objectToAdd];
else NSLog(@"Not mutable");
Why is that? Why is it claiming to be mutable and able to addObject:, but crashing unless I use a mutable copy?