开发者

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 i开发者_C百科s the case?

Thank you!!


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜