CS193P Assignment 3, Hint#5 - What is the model?

cs193p, ios, model-view-controller, objective-c

Solution

I do believe the model is the "program", an NSArray object. It can't be the description of the program cause there is no easy way to compute the "y" value given a NSString. You will have to re-parse the NSString into a stack (NSArray). As such, isn't it more direct to have the model as an NSArray/program?

Problem

I am working my way through the Stanford Fall 2011 iOS course: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/ I am onto assignment#3: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/assignments/Assignment%203_2.pdf As a summary, prior assignments have asked to build a regular calculator and now this assignment is asking us to push this calculator unto a Nav controller and create a segue from that CalculatorViewController to a GraphViewController that would plot the function stored in the "CalculatorBrain". This CalculatorBrain was the model for the original CalculatorViewController. Hint#5 keeps on talking about the fact that now the model for the GraphViewController is different than the model of the CalculatorViewController and I can't figure out what he means by that. The only way I have been able to build the new MVC is by creating a protocol in the GraphView (view) of the GraphViewController with an object called "dataSource" of type ID. And then in the GraphViewController: adopting that protocol, instantiating the GraphView and setting itself as the datasource: ``` -(void) setGraphView:(GraphView *)graphView { _graphView=graphView; self.graphView.dataSource=self; } ``` And then in the original CalculatoViewController, using the prepareForSegue to pass the program to the GraphViewController: ``` -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"Graph"]) { GraphViewController *myGraphViewController = segue.destinationViewController; myGraphViewController.myCalculator=self.myCalcBrain; } } ``` So that seems to work fine. So if that works, that means that the GraphViewController's model is really the original Calculator Brain that he specifically said it is not! I mean isn't the fact that, during the segue, I am assigning to the Graphviewcontroller calculator property the calculator model instance from the original CalculatorViewController and then using a protocol to return the Y value from the GraphViewController to the GraphView means that the model for the GraphViewController is really just the original CalculatorBrain model.

Original source