Vivek Subramanian
Vivek Subramanian

Reputation: 1234

isMemberOfClass problem

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!!

Upvotes: 0

Views: 680

Answers (1)

walkytalky
walkytalky

Reputation: 9543

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");

Upvotes: 2

Related Questions