How to compare two NSInteger?

Ahsan picture Ahsan · Feb 28, 2012 · Viewed 30.5k times · Source

How do we compare two NSInteger numbers ? I have two NSIntegers and comparing them the regular way wasnt working.

if (NSIntegerNumber1 >= NSIntegerNumber2) {
    //do something
}

Eventhough, the first value was 13 and the second value was 17, the if loop is executing

Any idea ?

Answer

justin picture justin · Feb 28, 2012

NSInteger is just a typedef for a builtin integral type (e.g. int or long).

It is safe to compare using a == b.

Other common operators behave predictably: !=, <=, <, >= et al.

Finally, NSInteger's underlying type varies by platform/architecture. It is not safe to assume it will always be 32 or 64 bit.