Amazon.com Widgets Question: exceptionDuringOperation::: and NSDecimalNumberHandler protocol
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 20, 2013, 12:29:16 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Newbie Corner
| | |-+  Question: exceptionDuringOperation::: and NSDecimalNumberHandler protocol
Pages: [1]   Go Down
Print
Author Topic: Question: exceptionDuringOperation::: and NSDecimalNumberHandler protocol  (Read 312 times)
[I code:forFun]
Newbie
*
Posts: 12






« on: May 26, 2012, 05:58:20 PM »

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:

Code: (Objective-C)
-(NSDecimalNumber *)addNum1:(NSDecimalNumber *)num1 andNum2:(NSDecimalNumber *)num2
{
    NSDecimalNumber *result = [num1 decimalNumberByAdding:num2 withBehavior:_behavior];
    return result;
}

_behavior is defined beforehand (in the class's init method) as follows:

Code: (Objective-C)
_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:
-rounding mode
-scale
– exceptionDuringOperation:error:leftOperand:rightOperand:

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!
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.