i have property called total
nsdecimalnumber
. in switch statement i'm trying simple addition , subtraction on number keep getting 'unrecognized selector sent instance
' error. here code:
switch (t) { case 0: { if (_zero == yes) { _total = [_total decimalnumberbysubtracting:[nsdecimalnumber decimalnumberwithstring:@"4.5"]]; = (uiimageview *)[self.view viewwithtag:7]; i.hidden = yes; } else { nsdecimalnumber *fourpointfive = [[nsdecimalnumber alloc] initwithdecimal:[[nsnumber numberwithfloat:4.5] decimalvalue]]; _total = [_total decimalnumberbyadding:fourpointfive]; = (uiimageview *)[self.view viewwithtag:7]; i.hidden = no; } break;
in same method, before switch statement initialize it:
_total = [[nsdecimalnumber alloc] initwithdecimal:[[nsnumber numberwithfloat:0] decimalvalue]];
and in @interface:
@property (strong, nonatomic) nsdecimalnumber *total;
update:
changed initialization to:
_total = [[nsdecimalnumber alloc] initwithstring:@"0"];
but it's still crashing. removed other references decimalvalue
.
this error message get:
terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfnumber decimalnumberbyadding:]: unrecognized selector sent instance
on ios nsnumber's decimalvalue returns nsdecimal, not nsdecimalnumber.
Comments
Post a Comment