Hello : )
While working with the NSDecimalNumber class, I've implemented a few functions to add and subtract numbers.
I'd like to properly implement the NSDecimalNumberBehaviors protocol.
My 'calculator' class has an addition method:
-(NSDecimalNumber *)addNum1:(NSDecimalNumber *)num1 andNum2:(NSDecimalNumber *)num2
NSDecimalNumber *result = [num1 decimalNumberByAdding:num2 withBehavior:_behavior];
_behavior is defined beforehand (in the class's init method) as follows:
_behavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:NSDecimalNoScale raiseOnExactness:YES raiseOnOverflow:YES raiseOnUnderflow:YES raiseOnDivideByZero:YES];;
Apple's documentation states that three methods are required to implement the NSDecimalNumberBehaviors protocol as seen here:
My question is, can someone provide an example of how to properly conform to the protocol? More specifically, I'm trying to figure out whether the (exceptionDuringOperation:error:leftOperand:rightOperand:) method needs to be included within my (addNum1:andNum2:) method somehow, or is it supposed to be a separate method within the 'calculator' class. What would this class look like with the protocol properly implemented? I'm not getting the picture yet.
Have I provided enough information to answer this question? (I have the 3rd edition, not with me at the moment : ), and am working through it to become knowledgeable). Thanks!