-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?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Son Nguyen
  • 3,481
  • 4
  • 33
  • 47
  • 1
    Are you sure you are recompiling your project properly when you modified your source code? You might be accidentally running the old source which would cause the xcode debugger to skip any added lines. NSInteger is just an alias for a int (or maybe int64?) type. Try adding a print statement NSLog("count = %d", count); – Akusete Jul 21 '10 at 04:14
  • I already use command + shift + K to clear cache then re-build project, I tried to debug this code many times, the count is changed, poor me :( – Son Nguyen Jul 21 '10 at 04:28

1 Answers1

0

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
  • 18,639
  • 11
  • 76
  • 110