Sorry if this is basic, but I can’t get my head around this. I have an array and would like to go through every single object in it and see if it isEqualToString:@”something”. If tried this, but it will crash:
for (int i = 0; i < ([myNSMutableArray count]); i++) {
NSLog(@"i = %i", i);
if ([[myNSMutableArray objectAtIndex:i] isEqualToString:@"something"]) {
...
} else {
...
}
}
I’ll get:
2011-07-14 13:38:40.983 MNs[21416:207] i = 0
2011-07-14 13:38:40.985 MNs[21416:207] -[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x4c976f0
2011-07-14 13:38:40.987 MNs[21416:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x4c976f0'
Any help would be very much appreciated. Thanks in advance!
EDIT:
Sorry, I forgot. This is how I created the array:
NSMutableArray *myNSMutableArray = [[NSMutableArray alloc] init];
for (int x = 0; x < 30; x++) {
[myNSMutableArray addObject:@""];
[myNSMutableArray addObject:@"something"];
[myNSMutableArray addObject:@""];
}
EDIT2:
So sorry, the problem was that I tried to copy a mutable array … so all of your answers are correct, I just need to pick one now, I guess.
Try This,