{NSDecimalNumber integerValue} behaving strangely in iOS8

The result for integerValue is surprising, but from what I understand as documented:

NSDecimalNumber inherits from NSNumber. In the subclassing notes from NSNumber it is stated that "... subclass must override the accessor method that corresponds to the declared type—for example, if your implementation of objCType returns “i”, you must override intValue ..."

objCType is set to the inner pointer, so it should be the same as for NSNumber.

NSDecimal does not override intergerValue. It does override doubleValue, so that should work fine.

The only thing that makes me wonder: it seems it does not override intValue either ...


What a great bug! I just found myself tricked by it. So, just to conclude dogsgods answer:

Do NOT:

NSInteger x = [myDecimalNumber integerValue];

Instead, do THIS:

NSInteger x = (NSInteger)[myDecimalNumber doubleValue];