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.
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?
I hate to answer this for you, since that's what you are supposed to do, but I do believe you are over thinking it, so here's what he wants you to realize/do:
Your model will be a new class that inherits from the model from the original calculator. That's why he says you will only need to create the view and controller from scratch. You will have to create a model class too, but a lot of the necessary code already exists in the old calc model, so you just inherit that and add the necessary additional functionality.
Hope that helps, and glad to see that you are using those courses. They are a great free tool!
I struggled a little with this question too when I was doing that assignment. I came to the conclusion (rightly or wrongly) that the model is just a formula - which seems like the conclusion you've come to, which while not being the calculator brain class, is very closely related to it!
edit:
I've just gone back and looked at my calculator program (i'm currently on the flickr assignment, so haven't looked at it in a while)
Looking at the basic calculator, the model was a "calculatorbrain" object
in the hints of the assignment it says
Don’t get this Controller’s Model confused with your CalculatorViewController’s Model. THEY ARE DIFFERENT. And don’t over-think this. Your new Controller’s Model is near at hand!
the graphview controller's model I have is a program. As in the program as defined in the calculatorbrain - just a stack of operations (NSArray) rather than a calculatorbrain. I just passed the current program via the segue into the graphview controller.
To me it seems to fit the details of the hint - the program is close at hand when you segue to the graph, but it it's not the same as the model of the calculator.
The hint doesn't say that it's not related to the model though.
But I'm a bit of an iOS n00b too, so this is just my take!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With