Do you have an NSNumberFormatter applied to unitaryPrice somewhere that is not set to generate decimal numbers? The documentation indicates that generating NSDecimalNumbers is on by default, but just dragging the NSNumberFormatter to an empty XIB over here doesn't start with it ticked off in the object attributes.

If that's not it you might try setting a breakpoint on your accessor and seeing where it's getting set to an NSNumber.

Ashley


On Jan 8, 2009, at 10:49 AM, Davide Benini wrote:

Hello folks,
I have run into a strange issue.
I have a LineItem class featuring a NSDecimalNumber *unitaryPrice property. The property works allright all across my app, except in a single view controller.

I have this LineItemDataPickerViewController (UIViewController subclass) with

@property (nonatomic, retain) LineItem *lineItem;

Before displaying it, I set

controller.lineItem = aLineItem;

When the controller is displayed, in the viewWillDisplay:animated: method, I need to set the unitaryPrice value in the appropriate field, but before I perform some rounding.

NSDecimalNumberHandler *roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundBankers scale:2 raiseOnExactness:FALSE raiseOnOverflow:TRUE raiseOnUnderflow:TRUE raiseOnDivideByZero:TRUE]; NSDecimalNumber *roundedAmount = [lineItem.unitaryPrice decimalNumberByRoundingAccordingToBehavior:roundingBehavior];

And here the application terminates and I get this error message

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFNumber decimalNumberByRoundingAccordingToBehavior:]: unrecognized selector sent to instance 0x10755e0'

for what it'w worthm, I tried also the following change, which was useless. NSDecimalNumber *roundedAmount = (NSDecimalNumber *) [lineItem.unitaryPrice decimalNumberByRoundingAccordingToBehavior:roundingBehavior];

I spent a couple of hours analysing the flow with the debugger. The controller.lineItem property is correctly set, and the lineItem.unitaryPrice object is seen as a NSDecimalNumber until BEFORE the LineItemDataPickerViewController is loaded and viewWillAppear:animated is called. Then, inside this method, lineItem.unitaryPrice is seen as an "out of scope" NSCFNumber.

I've been googling, and this discussion here is the closest thing I found to my issue:

http://www.cocoadev.com/index.pl?NSDecimalNumbersSeenAsNSNumbers

Any suggestion? Could this be a bug?

Davide

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to