I'm trying to iterate through an NSArray and check if an objectAtIndex is equal to a string.
NSLog(@"%@", myArray) // 3 items. 1 of them is "a"
for (id object in myArray)
{
NSLog(@"What"); // 3 times
if ([object isEqual:@"a"]) {
NSLog(@"Hello"); // Never gets executed
}
}
The problem is, the NSLog in the if statement never gets executed?
Edit
(
(
a
),
(
01
),
(
a
),
(
03
)
)
When I set it to isEqualToString, I get this error:
2015-03-30 14:42:54.206 MyApp[1575:50954] -[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x7fe721ce3bf0
2015-03-30 14:42:54.215 MyApp[1575:50954] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x7fe721ce3bf0'
isEqualToString:is the better choice, butisEqual:should still work. Please post the log so we can see what's actually inmyArray. I don't think@"a"is in there.isEqual:andisEqualToString:should both work; the latter is a performance optimization.