jazzedge
12/2/2017 - 6:19 AM

Swift - MVC

See:https://makeapppie.com/2016/09/23/why-do-we-need-delegates-in-ios-and-watchos/

01. Model

Describes and acts upon or modifies data. There is no user I/O

02. View

Deals with all user interaction. It tells us about the state of the view and it can change the view's appearance and behaviour. It never interacts with the data.

03. Controller

Connects the Model and View. It coordinates what happens in the view. 
If a user presses a button on the view, the controller responds to that event. 
If that response means sending messages to the model, the view controller does that. 
If the response requires getting information from the model, the controller does that too. 
In Xcode, @IBOutlet and @IBAction connect Interface Builder files containing views to the view controller.

The key to MVC is communication. To be more accurate, the lack of communication. MVC takes encapsulation very seriously.  The view and the model never directly talk to each other. The controller can send messages to the view and the controller. The view and controller may do an internal action to the message sent as a method call or it may return a value to the controller. The controller never directly changes anything in either the view or the model.

So to summarize, a view, a model and a controller cannot directly change a property in each other. A view and a model may not talk to each other at all. A view can tell the controller there is a change in the model. A controller can send messages in the form of method calls to the view and the model and get the responses back through that method.