I always seem to run into trouble with NSDecimalNumber! Today, I get this error:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFNumber decimalNumberByDividingBy:withBehavior:]: unrecognized selector sent to instance 0xd1fb10'"
Here is the source of the error:
- (void)setUpInstance {
static NSDecimalNumberHandler* roundingBehavior = nil;
if (roundingBehavior == nil) {
roundingBehavior = [[NSDecimalNumberHandler alloc] initWithRoundingMode:NSRoundDown scale:2 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
}
NSDecimalNumber *amount = viewController.aDecimalNumber;
NSDecimalNumber *actualValue = viewController.anotherDecimalNumber;
integralPortion = [amount decimalNumberByDividingBy:actualValue withBehavior:roundingBehavior];
...
}
The docs define the method as:
-(NSDecimalNumber*)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber
withBehavior:(id<NSDecimalNumberBehaviors>)behavior
I must not be interpreting the "(id<NSDecimalNumberBehaviors>)behavior
" argument correctly. Isn't that just ANY object as long as it conforms to the NSDecimalNumbersBehaviors protocol?
What am I'm doing wrong? Code examples would be very helpful.
Happy Friday!