I want to set a BOOL value as true false format to a NSMutableDictionary (which will use as a JSON Dictionary of the API Request). I tried both of the following methods. But those are NOT the correct format requested by the API (API needs the BOOL value as true/false type not as 1/0).
BOOL isDefault = YES;
[dicTemp setValue:[NSString stringWithFormat:@"%c", isDefault] forKey:@"is_default"];
//[dicTemp setValue:[NSNumber numberWithBool:isDefault] forKey:@"is_default"];
Can anyone have an ides
BOOL
can be wrapped in an NSNumber
object:
dicTemp[@"is_default"] = @YES;
(This code is using the newish Objective-C Literals syntax).
If you are old-fashioned (nothing wrong with that), then the above statement is the same as:
[dicTemp setObject:[NSNumber numberWithBool:YES]
forKey:@"is_default"];
To test later:
NSNumber *numObj = dicTemp[@"is_default"];
if ([numObj boolValue]) {
// it was YES
}
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