Jenya Kyrmyza
Jenya Kyrmyza

Reputation: 327

Can't compare values in if statement

I'm new to ios. I want to check if statement is true, but this condition gives true everytime even when it's false.

 NSMutableArray *passengers=loginObj.passengers;
 PassengerObj *passenger=[passengers objectAtIndex:0];
    if([[passenger checkedIn] objectAtIndex:0])
    {
       [somestatement];
    }

in debugger

_checkedIn  __NSCFArray *   @"1 object" 0x168b8200
   >[0] __NSCFBoolean * @"0"    0x37e696d4

Upvotes: 1

Views: 51

Answers (1)

Arc676
Arc676

Reputation: 4465

Assuming your array only contains strings that contain a 1 or a 0, you can compare the string:

if ([[[passenger checkedIn] objectAtIndex:0] isEqualToString:@"0"])

Of course it would be more readable to have an array of NSNumbers and use

if ([[[passenger checkedIn] objectAtIndex:0] boolValue])

Upvotes: 4

Related Questions