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!
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];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.