Joshua Joshua - 7 months ago 39
Objective-C Question

Checking if a NSInteger is odd or even

I have been trying to check whether an NSInteger is odd or even. I have found a way to do it using C but it doesn't work with Objective-C. How would I do this?

Answer Source

NSInteger is defined as int (or long on some environments). So checking on oddity is like for plain int:

NSInteger num;
if (num % 2)
  // odd
  // even
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download