I am trying to perform logic based on the values of two integers. Here I am defining my integers, and I also have NSLog so I can see if the values are correct when I run the code:
int theHikeFlag = (int)[theNewHikeFlag objectAtIndex:(theID-1)];
NSLog(@"theHikeFlag: %@",theHikeFlag);
int fromTheDB = [self.detailItem hikeFlag];
NSLog(@"fromTheDB: %d",fromTheDB);
And here is the logic:
if (theHikeFlag==1) {
hikeString=@"You have";
}
else if (theHikeFlag==0) {
hikeString=@"You have not";
}
else {
if (fromTheDB==1) {
hikeString=@"You have";
}
else {
hikeString=@"You have not";
}
}
As an example of how this code is working. When theHikeFlag=1 and fromTheDB=0, the code bypasses the if and the else if and goes straight to the else and sets hikeString="You have not". This means that my result is irrelevant of theHikeFlag and is based on the fromTheDB integer.
Since you cannot store
ints in an array, the lineis not doing what you think it should. You need to pull the data from
NSNumber, not cast toint.The reason why the log output is correct is a bit funny: you made two mistakes in a row! First, you re-interpreted a pointer as an
int, and then you letNSLogre-interpret it as an object again by adding a format specifier%@that is incompatible withint, but works fine with pointers! Since theintvalue contains a pointer toNSNumber,NSLogproduces the “correct” output.