0

I have an array called binaryArray.

Initalised with NSMutableArray *binaryArray = [[NSMutableArray alloc] init];

I add 0's or 1's into the array using [binaryArray addObject:[NSNumber numberWithInt:1]];

I then reference this array in a tableView with

id resultBinary = [binaryArray objectAtIndex:indexPath.item];

    if (resultBinary == 0) {
        ...
    } else {
        ...
    }

However, even if resultBinary is 0, it never hits

Niall Kiddle
  • 1,477
  • 1
  • 16
  • 35

2 Answers2

1

try this

if ([resultBinary integerValue] == 0) {
    ...
} else {
    ...
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

As NSNumber is a class that helps to store numeric types as object. So when comparing with 1, it is actually comparing with numeric type not with NSNumber.

So changing it to NSNumber literals works.

id resultBinary = [binaryArray objectAtIndex:indexPath.item];

    if ([resultBinary isEqual:@0]) {
        [cell.starImage setImage:[UIImage imageNamed:@"Results_star_empty"]];
    } else {
        [cell.starImage setImage:[UIImage imageNamed:@"Results_star_filled"]];
    }

Objective-C Literals

Pooja Gupta
  • 785
  • 10
  • 22
Niall Kiddle
  • 1,477
  • 1
  • 16
  • 35