I've looked everywhere for this, online, on stack overflow and cannot still work out what I'm doing wrong.
I'm trying to add an element to an existing NSMutableArray. But it crashes on line 4:
-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x897b320
The code:
NSMutableArray *mystr = [[NSMutableArray alloc] init];
mystr = [NSArray arrayWithObjects:@"hello",@"world",@"etc",nil];
NSString *obj = @"hiagain";
[mystr addObject:obj];
What am I doing wrong? This is driving me crazy!!!
You array is not mutable!. Use NSMutableArray
mystr = [NSMutableArray arrayWithObjects:@"hello",@"world",@"etc",nil];
You get unrecognized selector since NSArray
does not contain the addObject method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With