CS193P Purpose 3, Tip # 5 - What is the model?

I work through an IOS course at Stanford in the fall of 2011: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/

I get assignment # 3: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/assignments/Assignment%203_2.pdf

As a summary, the preliminary tasks were asked to build a regular calculator, and now this task asks us to push this calculator to the Nav controller and create a segue from this CalculatorViewController for GraphViewController, which will build the function stored in the "CalculatorBrain". This CalculatorBrain was the model for the original CalculatorViewController.

Tip # 5 continues to say that the model for GraphViewController is now different from the CalculatorViewController model, and I can't figure out what it means.

The only way I was able to create a new MVC was to create a protocol in the GraphView (view) of the GraphViewController with an object called the "dataSource" type identifier. And then in GraphViewController: accepting this protocol, instantiating GraphView and setting yourself up as a data source:

-(void) setGraphView:(GraphView *)graphView { _graphView=graphView; self.graphView.dataSource=self; } 

And then in the original CalculatoViewController, using prepareForSegue to pass the GraphViewController program:

 -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"Graph"]) { GraphViewController *myGraphViewController = segue.destinationViewController; myGraphViewController.myCalculator=self.myCalcBrain; } } 

So this works fine. Therefore, if this works, it means that the GraphViewController model is indeed the original Brain calculator, which he specifically said that it is not!

I mean, not that during segue I assign the calculator property of the Graphviewcontroller to the instance of the calculator model from the original CalculatorViewController, and then using the protocol to return the Y value from the GraphViewController to GraphView, this means that the model for GraphViewController is really the original model CalculatorBrain

+6
source share
6 answers

I believe that a model is a "program", an NSArray object. This cannot be a description of the program, because there is no easy way to calculate the value of "y" given NSString. You will have to re-parse the NSString onto the stack (NSArray). So, isn’t it more direct that the model is an NSArray / program?

+3
source

I hate answering this for you, as this is what you should do, but I believe that you have already thought about it, so that he wants you to understand / do:

Your model will be a new class that inherits the model from the original calculator. Therefore, he says that you only need to create a view and controller from scratch. You will also have to create a model class, but in the old calc model there is already a lot of necessary code, so you just inherit it and add the necessary additional functions.

I hope this helps, and I am glad to see that you are using these courses. This is a great free tool!

+1
source

I also worked a little with this question when I was doing this task. I came to the conclusion (right or wrong) that the model is just a formula that seems to come to the conclusion, which, although it is not a class of the brain of a calculator, is very closely related to it!

change

I just returned and looked at my calculator program (now I am in flickr assignment, so I did not look at it after a while)

Looking at the basic calculator, the model was a calculatorbrain object

in assignment clues he says

Do not use this controller model, confused with your CalculatorViewControllers model. THEY ARE DIFFERENT. And don’t think about it. Your new controller model is on hand!

The graphical controller model I have is a program. As with the program defined in the calculator, it is just a stack of operations (NSArray), not a calculator. I just passed the current program through segue to the graph controller.

It seems to me that it corresponds to the details of the tooltip - the program is at hand when you go to the chart, but this is not the same as the calculator model.

The tooltip does not say that it is not related to the model.

But I also have a bit of iOS n00b, so this is just my business! A.

+1
source

The model should just be NSString, describing the "program" that you are going to plot. As in the program that returns you the Brain calculator!

 id program = [self.dataSource.brain program]; 
+1
source

My model was also a "program"!

+1
source

@Lee Cjin Pheow, you're right. As this course developed, this became more apparent. So the model is just NSArray supporting the program. I think my confusion was due to the assumption n00b that I made that a model in MVC should be its own class / file and therefore my search for the model class / file. As I progress, I see that the professor has MVC, where the Model is really just a property, for example, which sits in the Controller. I just have to support Yellow, don't cross the lines in my simple mind.

0
source

Source: https://habr.com/ru/post/913841/


All Articles