I am trying to compare two integers. One is the row
of an NSIndexPath
, the other is the count
of an NSArray
. The row
is equal to 0 and the count
is equal to 2. I have them in an if
statement as follows:
if([self.selectedSetpoint row] < ([self.theCategories count]-3))
{
//Do true stuff
}
So by my math, the if
statement should be false as I am comparing 0 < -1
. However, I keep getting this statement coming through as true, and the block inside the if
is being run. I have tried to NSLog
the values to make sure that I am not just getting the wrong value. I placed this right BEFORE the if
statement:
NSLog(@"%d",[self.selectedSetpoint row]);
NSLog(@"%d",[self.theCategories count]-3);
NSLog(@"%@",[self.selectedSetpoint row] < ([self.theCategories count]-3)?@"Yes":@"No");
and got this on the console:
2012-07-17 08:58:46.061 App[61345:11603] 0
2012-07-17 08:58:46.061 App[61345:11603] -1
2012-07-17 08:58:46.062 App[61345:11603] Yes
Any ideas why this comparison is coming up as true? Am I misunderstanding something about comparing integers?
I have another if statement just above this one that compares
[self.selectedSetpoint row]<([self.theCategories count]-2)
Which is 0 < 0
, and it works fine (returns NO
). So I feel like there is some issue with the use of negative integers that I am not getting.
Thank you in advance.