I am trying to make Class methods (I do not want instance methods and variables) for a calculator class in Objective-C but I am running into issues. I have the following .h file:
#import <Foundation/Foundation.h>
@interface Calc : NSObject
{
NSNumber* accumulator;
}
//Acumulator Methods
+ (void) setAccumulator: (NSNumber *) value;
+ (void) clear;
+ (NSNumber *) accumulator;
//Arithmatic metods
+ (void) add: (NSNumber *) value;
+ (void) subtract: (NSNumber *) value;
+ (void) multiply: (NSNumber *) value;
+ (void) divide: (NSNumber *) value;
+ (void) setCurrentOperation: (NSString *) o;
+ (NSString *) currentOperation;
Then when I try to define any one of the methods in the .m file I receive the error: "instance variable 'x' accessed in class method". An example of a method in my .m file with this error being:
+ (void) setAccumulator: (NSNumber *) value
{
accumulator = value;
}
Could someone perhaps explain why this error occurs as well as help me fix it? Thanks!