views:

117

answers:

1

Hello,

My app crash when I try to access any property of my NSDecimalNumber amount_before_current_year:

[amount_before_current_year stringValue]
Program received signal:  “EXC_BAD_ACCESS”.

The object is a NSDecimalNumber as shown in the image attached.

I created it in the viewDidLoad, it exists in the header file:

.h
...
    NSDecimalNumber *amount_before_current_year;
...
@property (nonatomic, retain) NSDecimalNumber *amount_before_current_year;
...

also in the implementation file:

@synthesize amount_before_current_year;


    amount_before_current_year = [NSDecimalNumber decimalNumberWithString:@"100.00"];

here I call it again:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *test = [amount_before_current_year stringValue]; // HARD CRASH !!!

so, I don't know what to do now, I've spent some hours with this .....

any ideas ??????

thanks, r. alt text

+3  A: 

You need to either retain amount_before_current_year when you assign to it, or use dot notation to assign to it:

self.amount_before_current_year = [NSDecimalNumber decimalNumberWithString:@"100.00"]

Since you declared the property with the retain attribute, the synthesized setter will automatically send a retain message, as well as releasing any previous value. I recommend this approach.

Rob Jones
thanks, this works: amount_before_current_year = [[NSDecimalNumber decimalNumberWithString:@"100.00"] retain];time to re-read again and again basic objective-C ...thanks!!!
mongeta