I have set a bool value for key TCshow in my NSUserDefault, I want to run a nslog test whether the key is saved or not, and i m trying to printout the bool value. here is my code but it s not working, any suggestions?
- (IBAction)acceptAction:(id)sender {
//key store to nsuserdefault
self.storedKey = [[NSUserDefaults alloc] init];
[self.storedKey setBool:YES forKey:@"TCshow"];
//trying to print out yes or not, but not working...
NSLog(@"%@", [self.storedKey boolForKey:@"TCshow"]);
}
Normally a bool is printed as either a 0 or a 1 by std::cout , but more often than not, if you're printing a bool , it's better to see true/false .
As in C++ true refers to 1 and false refers to 0. In case, you want to print false instead of 0,then you have to sets the boolalpha format flag for the str stream. When the boolalpha format flag is set, bool values are inserted/extracted by their textual representation: either true or false, instead of integral values.
%@
is for objects. BOOL
is not an object. You should use %d
.
It will print out 0
for FALSE/NO and 1
for TRUE/YES.
you should use
NSLog(flag ? @"Yes" : @"No");
here flag
is your BOOL
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With