{NSDecimalNumber integerValue} behaving strangely in iOS8

前端 未结 4 1151
予麋鹿
予麋鹿 2020-12-17 20:42

OK team, this is weird. [NSDecimalNumber integerValue] is behaving strangely.

I\'m sat at a breakpoint, trying to figure out why some parts of my app are broken in i

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 21:09

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

提交回复
热议问题