BOOL to NSString BOOL to NSString objective-c objective-c

BOOL to NSString


Use a ternary operator:

BOOl isKind= [thing isKindOfClass:[NSString class]];NSLog(@"Is Kind of NSString: %d", isKind);NSLog(@"Is Kind of NSString: %@", isKind ? @"YES" : @"NO");


You need a formatting specifier in your format string:

NSLog(@"Is Kind of NSString: %@", ([thing isKindOfClass:[NSString class]]) ? @"YES" : @"NO");


In the background BOOL acts like an int type so you can use %i to test for a BOOL type’s value in NSLog:

BOOL a = YES;BOOL b = NO;NSLog(@"a is %i and b is %i", a, b);// Output: a is 1 and b is 0