1
votes

This is the error I keep getting:

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

I understand that the error is saying that I am calling NSMutableArray functionality on a NSArray but in my code I only have NSMutableArray functionality...

View Controller.h:

@property (copy, nonatomic) NSMutableArray *exampleMessages;
//added NSMutableArray property named exampleMessages

View Controller.m:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.exampleMessages = [[NSMutableArray alloc]initWithObjects:@"Example Message..", @"Example Message..",@"Example Message..",@"Example Message..",@"Example Message..", @"Example Message..",@"Example Message..",@"Example Message..", nil];

Am I creating the NSMutable array incorrectly?? Please help!

1

1 Answers

1
votes

NSMutableArray cannot be copy.

Change

@property (copy, nonatomic) NSMutableArray *exampleMessages;

to

@property (nonatomic) NSMutableArray *exampleMessages;

I've done this to myself at least three times so far. It's a real pain. I'm sorry to inform you there is no mutableCopy attribute for properties, I looked this up also.

The best answer I have for that is overriding -setExampleMessages:.

- (void)setExampleMessages:(NSMutableArray *)exampleMessages {
    _exampleMessages = [exampleMessages mutableCopy];
}