I am crashing at runtime when i pop last element from NSMuttable array.I am getting all element fine but when i acess last element it will give error.
-(id)popOperand{
id operandObject = [self.operandStack lastObject];
if(operandObject) [self.operandStack removeLastObject];
return operandObject;
}
For eg:- if in my stack i have “8”(Its NSNumber object) “+”(Its NSString object) 2(Its NSnumber Object).
NSNumber *rightOperand = [self popOperand];
NSString *operation = [self popOperand];
NSNumber *leftOperand = [self popOperand];//when i acess 8 it shows empty array other element is getting fine;
My question is why i am not able to get last object while this function is working fine for other elememts.
EDIT : At run time when after poping 2 it show stack( 8 +) but after i poped + it show stack() empty.But The “leftOperand” is not getting value. I am not using ARC.
Please ellaborate it.
Thanks.
If you aren’t using ARC then you have memory management issues:
Try this version, which returns a
retain‘d andautorelease‘d object, which conforms to the naming convention of the method: