Mobile Development

Model - View - Controller

iOS templates new projects in Xcode using the MVC pattern. That is to say, they give you a separate entity for each part of the MVC pattern. Keeping each part of MVC as separate as possible allows for reusability, maintenance and clean code.

The above diagram illustrates the MVC pattern and is broken out into model, view and controller and linked between them is the action. See reference [1].

This chapter will be exploring the following topics:

  1. Model - Data storage
  2. View - UI as defined and created in a Storyboard
  3. Controller - Controller classes which typically override a UIKit class.

[Video] Introduction to MVC

The following video serves as an introduction to the MVC pattern and provides a helpful overview of the concept.

Introduction to MVC

https://www.youtube.com/watch?v=Y09RvzZ1mY8

Model

A model in an iOS application can be a simple class or struct that persists in memory. It can also be a file that is written to disk, which would presist through subsequent launches of your application. CoreData is a system that Apple provides as a robust model layer in your iOS applications.

Model objects encapsulate the data specific to an application and define the logic and computation that manipulate and process that data. [1]

Reference: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/ModelObject.html

View

Views are typically handled in a Storyboard, handled by Interface Builder within Xcode.

A view object is an object in an application that users can see. A view object knows how to draw itself and can respond to user actions. [1]

Controller

Deciding what to do once your user interacts with your application is handled by the controller. In your projects, this is the subclass of UIViewControllers, UITableViewControllers, etc.

A controller object acts as an intermediary between one or more of an application’s view objects and one or more of its model objects. Controller objects are thus a conduit through which view objects learn about changes in model objects and vice versa. [1]

Reference: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/ControllerObject.html

References

[1] - Cocoa Core - Model View Controller https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html

[2] Start Developing iOS apps today - Using Design Patterns https://developer.apple.com/library/mac/referencelibrary/GettingStarted/RoadMapOSX/books/StreamlineYourAppswithDesignPatterns/StreamlineYourApps/StreamlineYourApps.html