title: Don't know how to access property from class method in Xcode
body: <p>I want to access the property <code>storedValue</code> from the class method <code>popOperandOffStack:</code>, but I get an error. I read that you cannot access <code>storedValue</code> because it is a class method or something like that. Can anyone tell me how can I access <code>storedValue</code> or how can I make <code>storedValue</code> global so that I can use it in <code>popOperandOffStack:</code>?</p>
  
  <p>Here is my header: </p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @interface CalculatorBrain : NSObject
  
  - (void)pushOperand:(double)operand; // - = instance method
  - (double)performOperation: (NSString *)operation;
  
  @property (nonatomic,readonly) id program;
  
  + (double)runProgram:(id)program; // + = class method
  + (NSString *)descriptionOfProgram:(id)program;
  @end
  </code></pre>
  
  <p>And this is my m file:</p>
  
  <pre><code>#import "CalculatorBrain.h"
  
  @interface CalculatorBrain()
  @property (nonatomic,strong) NSMutableArray *programStack;
  @property (nonatomic) double storedValue;
  @end
  
  @implementation CalculatorBrain
  
  @synthesize programStack = _programStack;
  @synthesize storedValue = _storedValue;
  
  - (NSMutableArray *)programStack
  {
      if (_programStack == nil)
          _programStack = [[NSMutableArray alloc] init];
  
      return _programStack;
  }
  
  - (void)setOperandStack:(NSMutableArray *)programStack
  {
      _programStack = programStack;
  }
  
  - (void)pushOperand:(double)operand
  {
      [self.programStack addObject:[NSNumber numberWithDouble:operand]];
  }
  
  - (double)performOperation: (NSString *)operation
  {
      [self.programStack addObject:operation];
      return [[self class] runProgram:self.program];
  }
  
  - (id)program 
  {
      return [self.programStack copy];
  }
  
  + (NSString *)descriptionOfProgram:(id)program
  {
      return @"Implement this in Assignment 2";
  }
  
  + (double) popOperandOffStack:(NSMutableArray *)stack
  {
      double result = 0;
  
      id topOfStack = [stack lastObject];
      if (topOfStack) 
          [stack removeLastObject];
  
      if ([topOfStack isKindOfClass:[NSNumber class]])
      {
          result = [topOfStack doubleValue];
      } 
      else if ([topOfStack isKindOfClass:[NSString class]]) 
      {
          NSString *operation = topOfStack;
          if ([operation isEqualToString:@"+"]){
              result = [self popOperandOffStack:stack] + [self popOperandOffStack:stack];
          } else if ([operation isEqualToString:@"-"]){
              result = -[self popOperandOffStack:stack] + [self popOperandOffStack:stack];
          } else if ([operation isEqualToString:@"*"]){
              result = [self popOperandOffStack:stack] * [self popOperandOffStack:stack];
          } else if ([operation isEqualToString:@"/"]){
              double divide = [self popOperandOffStack:stack];
              if(divide){
                  result = [self popOperandOffStack:stack] / divide;
              } else {
                  result = 0;
              }
          } else if ([operation isEqualToString:@"1/x"]){
              result = 1 / [self popOperandOffStack:stack];
          } else if ([operation isEqualToString:@"sqrt"]){
              double sqrtNumber = [self popOperandOffStack:stack];
              if (sqrtNumber &gt; 0){
                  result = sqrt(sqrtNumber);
              } else {
                  result = 0;
              }
          } else if ([operation isEqualToString:@"sin"]){
              result = sin( [self popOperandOffStack:stack]);
          } else if ([operation isEqualToString:@"cos"]){
              result = cos( [self popOperandOffStack:stack]);
          } else if ([operation  isEqualToString:@"MS"]){
              self.storedValue = [self popOperandOffStack:stack];
          } else if ([operation isEqualToString:@"MR"]){
              result = self.storedValue; //error here
          } else if ([operation isEqualToString:@"MC"]){
              result = [self popOperandOffStack:stack];
              self.storedValue = 0; //error here
          } else if ([operation isEqualToString:@"M+"]){
              result = [self popOperandOffStack:stack];
              self.storedValue = self.storedValue + result; //error here
          } else if ([operation isEqualToString:@"M-"]){
              result = [self popOperandOffStack:stack];
              self.storedValue = self.storedValue - result; //error here
          } else if ([operation isEqualToString:@"C"]){
              result = 0;
              while ( [self popOperandOffStack:stack] )
              {
                  //clear operands until returns NO
              }
          } else if ([operation isEqualToString:@"CE"]){
              result = 0;
              self.storedValue = 0; //error here
              while ( [self popOperandOffStack:stack] )
              {
                  //clear operands until returns NO
              }
          }   
  
          if (![operation isEqualToString:@"MS"] &amp;&amp; ![operation isEqualToString:@"CE"])
          {
              return result;
          } else {
              return self.storedValue;
          }
      }
      return result;
  }
  
  + (double)runProgram:(id)program
  {
      NSMutableArray *stack;
      if ([program isKindOfClass:[NSArray class]]) {
          stack = [program mutableCopy];
      }
      return [self popOperandOffStack:stack];
   }
  
  @end
  </code></pre>
  
  <p>I cannot use <code>self.storedValue</code>. What should I do besides changing the <code>+</code> (static method) to <code>-</code> (instance method) (I am not allowed to do that)?</p>