iphone - value get released from variable when value is float number -


i facing such strange issue right now, trying implement calculator in project demo. place want implement arc enable , project arc disable working in demo working perfect in project when try operation on float values application crashes says exc_bad_access(code 1.... below code

_currentvalue , _previousvalue in .h file

@property (retain,nonatomic) nsnumber* currentvalue;   @property (retain,nonatomic) nsnumber* previousvalue; 

in .m file there 2 methods face problem

- (nsstring *)calculatevaluetostring:(nsstring *)valuestring fortype:(enum state)type{      _currentvalue = [numberformatterformal numberfromstring:valuestring];      nslog(@"%@",_currentvalue);  //whatever number input prints here      [self calculatevalue]; // method called     state = type;                if (state != equal){         _previousvalue = _currentvalue;          nslog(@"%@",_previousvalue);  // print          _currentvalue = @0 ;     }       nslog(@"_previousvalue%@",_previousvalue);   // print      nslog(@"_currentvalue%@",_currentvalue);      // print     return [numberformatterformal stringfromnumber:_currentvalue];  }  - (void)calculatevalue{       switch (state) {          case plus:             _currentvalue = [nsnumber numberwithdouble:[_previousvalue doublevalue] + [_currentvalue doublevalue]];             break;         case minus:                        //get execute if operation -                nslog(@"%@",_currentvalue);  // has value      --->>>>>>> here app crash         nslog(@"%@",_previousvalue);   // app crashes here              _currentvalue = [nsnumber numberwithdouble:[_previousvalue doublevalue] - [_currentvalue doublevalue]];                 nslog(@"%@",_currentvalue);                 // work in demo arc enable              break;         case multiple:             _currentvalue = [nsnumber numberwithdouble:[_previousvalue doublevalue] * [_currentvalue doublevalue]];             break;         case divide:             _currentvalue = [nsnumber numberwithdouble:[_previousvalue doublevalue] / [_currentvalue doublevalue]];             break;         default:             break;     } } 

you're accessing instance variables directly, , using manual reference counting. isn't going work.

all of memory management done in synthesised accessor methods, must use property accessors, e.g:

self.currentvalue = ....; 

never

_currentvalue = ...; 

or bypassing of retain / release calls accessors doing you.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -