views:

27

answers:

1

Hi All,

I'm trying to log if an object in my mutable array is a member of the class NSString. Here is my code:

 id obj = [mutArr objectAtIndex:1];
 BOOL classMem = [obj isMemberOfClass:[NSString class]];
 NSLog(@"%@", classMem);

Instead of printing YES or NO, I get the output (null). Can you please tell me why this is the case?

Thank you!!

+2  A: 

BOOL is not an object, so shouldn't be logged with %@. Log it with the format string %d instead. Or, if you want more legible output, you can use:

NSLog(@"%@", classMem ? @"YES" : @"NO");
walkytalky
And when you've fixed that, you'll find that almost none of the strings in the array answers yes. NSString is a class cluster and almost all strings are actually instances of subclasses of NSString. You should be using `-isKindOfClass:` not `-isMemberOfClass:`
JeremyP
wow, great, thank you so much!! :)
NoobjectiveC