I know this doubt could be silly mistake. I am getting a variable from JSON string, it will have the status 1 or 0. If I do using first method(Code 1) it works. But if I do the second method (Cord 2) I am getting NO always. I don’t know what am I doing wrong. Please forgive me if the question is too silly.
Cord 1:
NSDictionary *drivingAlertResponse = [jsonResponseString objectFromJSONString];
BOOL isEnabled;
if ([[drivingAlertResponse valueForKey:@"alertStatus"] intValue] > 0) {
isEnabled = TRUE;
}else{
isEnabled = FALSE;
}
Cord 2:
BOOL isEnabled = [[[NSString stringWithFormat:@"%i",[drivingAlertResponse valueForKey:@"alertStatus"]] isEqualToString:@"1"]? @"TRUE": @"FALSE" boolValue];
I would just use NSString’s boolValue method. You can use it like so: