views:

113

answers:

1

I have a crazy problem when comparing an NSInteger to int, as follows:

NSInteger count = [dictionary count];

if (count == 0) {
    // Do something
}
else {
    // Do something
}

When the count is zero, the snipped code in the if clause is run, but when the count number is changed, the snipped code in the if clause is not run (this is correct), but the snipped code in the else clause is not run either. When I debug, the cursor always jumps over the else clause.

I tried to change count number to int or compare it as an NSNumber, but nothing changed.

Does anyone know how to solve this problem?

A: 

There is nothing related to NSInteger and int here. The logic of if else is that exactly one of them has to be called, no matter what happens. So, if none of them is called, something else happened wrongly. Can you just NSLog both of the if and else clause. It is also better if you show me what is inside if and else clause

vodkhang
Oh my god, after I restart my computer, this problem is gone :(
Son Nguyen
that's funny. Maybe something wrong with your XCode:), did you try to relaunch it
vodkhang
I did restart X-Code but there was nothing change until restart computer, maybe I need to re-install my X-Code :(
Son Nguyen
and the good practice here is accept answers
vodkhang