Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the Model-View-Controller pattern apply to iPhone development?

Recently I've been reading up on the MVC pattern and wish to apply it to my iPhone development. However, there seem to be so many variations of the pattern that I'm not sure exactly how it should be applied.

As far as I gather, the view will notify the controller of any actions which have been performed and the controller will in turn update the data model (if required). The data model will notify the view whenever a change to the data occurs and the view then updates it's display of the data appropriately.

In this basic model, the controller only has knowledge of the data model. However, I can't seem to figure out how to employ this design within my iPhone app.

The following page suggests an alternative version of the pattern where the controller has an awareness of both the data model and the view and all communication between the model and view is performed via the controller. It also seems to suggest that the model and view have access to the controller. Would I be right in suggesting that the data model interacts with the controller via some form of notification (notifications or KVO) and that the view interacts with the controller via actions?

Is this second model correct?

http://www.bogotobogo.com/DesignPatterns/mvc_model_view_controller_pattern.html

Many thanks,

Danny

like image 279
Danny Avatar asked Dec 27 '10 18:12

Danny


1 Answers

I found Paul Hegartys explanation on MVC in iOS very helpful. see his Stanford iTunes U video. MVC starts at minute 22.

edit
The link of the video doesn't bring you there as expected. it is 1. Introduction to Cocoa Touch, Objective-C, Tools, and MVC (September 21, 2010)

like image 189
vikingosegundo Avatar answered Sep 26 '22 15:09

vikingosegundo