Re: NSDecimalNumber seen as NSCFNumber; a bug? (not solved)
Re: NSDecimalNumber seen as NSCFNumber; a bug? (not solved)
- Subject: Re: NSDecimalNumber seen as NSCFNumber; a bug? (not solved)
- From: Davide Benini <email@hidden>
- Date: Fri, 9 Jan 2009 10:17:00 +0100
Upon this suggestion, I investigated further with the debugger.
Now I am more than sure than the value is not released, not in the
passages I describe here.
This is the scenario.
I have a UITableViewController. Rows is selected. willSelect or
didSelect methods (I tried both) do this
LineItemDataPickerViewController *controller =
[[[LineItemDataPickerViewController alloc]
initWithNibName:@"LineItemDataPickerView" bundle:nil] autorelease];
controller.lineItem = lineItem;
[self.navigationController pushViewController:controller animated:YES];
I put a breakpoint on this last line; here,
controller.lineItem.adjustedUnitaryPrice is a NSDecimalNumber. All
good so far.
Then the LineItemDataPickerViewController's viewWillApper:animated
method is invoked. Here's the relevant code:
-
(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[typePicker reloadAllComponents];
NSLog(@"%@", lineItem.unitaryPrice);
//etc...
I put a breakpoint here, to check on the types and values of lineItem
properties.
adjustedUnitaryPrice is now a NSCFNumber (rounded with 2 decimals
after the comma), but that's not all; lineItem.name, supposedly a
NSString is a NSCFString. Similarly, a NSArray property figures now as
NSCFArray.
Now, I know these are the abstract equivalent between NS classes, but
I wonder why the debugger correctly shows the NSClasses in the
UITableViewController and the NSCF classes in the
LineItemDataPickerViewController. More importantly, because of this
class mismatch, during the runtime method calls like
decimalNumberByRoundingAccordingToBehavior are not recognized.
Note that the controller.lineItem property is correctly set (@property
(nonatomic, retain) LineItem *lineItem; ) and synthesized; the
LineItem.h file is imported in both controllers.
So, something happens between the first controller willSelect:animated
invoke and the second controller willAppear, that changes my object
classes.
What do you suggest?
Davide
Il giorno 09/gen/09, alle ore 01:27, Quincey Morris ha scritto:
On Jan 8, 2009, at 08:49, Davide Benini wrote:
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'
By far the most common cause of an error like this (the class of the
object is not what you expect) is a memory management bug in your
code.
That is, the NSDecimalNumber object (to which something is holding a
pointer) has actually been improperly released and deallocated. By
chance, the same block of memory has since been reused for a
completely unrelated object (a NSNumber object, in this case).
Check to see that you've followed memory management rules
everywhere. (Look for a missing retain or an extra release.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden