Understanding the MVC design pattern

A common way to build iOS apps is by using the MVC design pattern.

MVC divides an app into three different parts:

  • Model: This handles data storage and representation, and data processing tasks.
  • View: This includes all the things that are on the screen that the user can interact with.
  • Controller: This manages the flow of information between model and view.

One feature of MVC is that view and model do not interact with one another; instead, all communication is managed by the controller.

For example, imagine you're at a restaurant. You look at a menu and choose something you want. Then, a waiter comes, takes your order, and sends it to the cook. The cook prepares your order, and, when it is done, the waiter takes the order and brings it out to you. In this scenario, the menu is the view, the waiter is the controller, and the cook is the model. Also, note that all interactions between you and the kitchen are only through the waiter; there is no interaction between you and the cook.

To find out more about MVC, you can refer to https://en.wikipedia.org/wiki/Model–view–controller.

To see how MVC works, let's learn a little more about controllers and classes. You will see what it takes to implement a view controller that is required to manage a collection view,  which is used in the Explore screen and the Restaurant List screen.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.251.37