You cant save BOOL
value in NSDictionary
directly because it is not an object. So first you will have to change it in NSNumber
then save it in NSDictionary
and then compare isKindOfClass:[NSNumber Class]
instead of comparing the [BOOL class]
.
Example:-
BOOL value = YES;
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithBool:value],@"Bool", nil];
id val = [dict valueForKey:@"Bool"];
if([val isKindOfClass:[NSNumber class]])
{
//NSNumber Class
}
EDIT:
You cant cast a BOOL
value into NSString
directly. If you want BOOL
value in NSString
format you will have to make your own methods. Here is a small example of this using macro
.
Define this macro
in which class you want to cast a BOOL
value to NSString
.
#define NSStringFromBOOL(aBOOL) aBOOL? @"YES" : @"NO"
Then simply call this -
NSString *bool_string = NSStringFromBOOL(YES);
NSLog(@"%@",bool_string);
It will print YES
instead of '1'.