I am new to iOS and Objective-C, I already know that in a class, the class's property you defined can only be initiated in an "instance" of that class.
But is there any mechanism in Objective-C that can store some data that can be used in the class's class method?
To be specific, I' m working on a quiet simple RPN Calculator app.
And according to the Stanford iOS Programming Dev(CS193P)'s tutorial, I create the RPN Calculator Controller's model named RPNCalculatorBrain, and there's a property (id)program
, and a class method +(double)runProgram:(id)program
.
(id)program
is essentially an array contained all the operand and operation entered by user.
The instructor in that class suggest using class method so that other class (in this program's situation, a functionGraphMVC) can pass (id)program
to this class method and get the result of the program( or, the function). So that the model RPNCalculatorBrain can be made as generic as possible.
and there's another class method +(double)runProgram:(id) program using:(NSDictionary*)variableValues
. it is the variable edition of the above class method. So in case there's a variable (X, a, b) in id(program)
, this class method can use (NSDictionary *)variableValues
to interpret the variable's value.
But Personally I want to improve this method, I was just wondering if I can store Calculator's special operation (π, e) AND the variable (x) in my model (CalculatorBrain), and give a class method +(void)setXValue();
to whoever wants use it. So I can store everything about Calculation in my model. But as far as I know, I can't store something that can be used in class method.
And store this information in NSUserDefault seems inappropriate, AND I have't read the Documentation about Core Data yet.
I know my idea seems to be a lithe strange and naive, and I certainly can use some alternate approach to do the same job, but I just want to know whether it is possible. Thanks!
If my description confuse you guys, please forgive me! My writing english is ...