Joshua Joshua - 30 days ago 7
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