Search code examples
iosexc-bad-accessnsdecimalnumber

iOS App terminates due to bad value of NSDecimalNumber


My iOS app terminates in Xcode simulator due to EXC_BAD_ACCESS error on following line

if ([amount.text isEqualToString:@""] || [chargeAmount floatValue] == 0.0) {

The complete block of code is

if ([amount.text isEqualToString:@""] || [chargeAmount floatValue] == 0.0) {
    // Focus on the poptip target.
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [transactionView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    [self performSelector:@selector(amountRequiredPopup) withObject:nil afterDelay:0.3];
    return;
}

I check amount.text in NSLog and it is showing the value but not the ChargeAmount. It seems there is bad value of chargeAmount. chargeAmount is defined in interface in .h file as follows:

NSDecimalNumber* chargeAmount;

I am new in objective C and iOS app development. Please suggest where is the issue? Thank you in advance.


Solution

  • Based on your last comment, as i think the issue is that you have assigned a value of another type into your chargeAmount variable, search all your code related to chargeAmount and post there, in some part of your code you are assigning a value of type NSMutableAttributedString to your chargeAmount variable and then when you call [chargeAmount floatValue] crash because NSMutableAttributedString don't have any method called floatValue

    Hope this helps you