Understanding model objects

As you learned in Chapter 13, Getting Started with MVC and Collection Views, a common design pattern for iOS Apps is MVC. To recap, MVC divides an app into three different parts:

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

Let's look at the design of the Explore screen that you saw during the app tour:

Now, build and run your app, and the EXPLORE screen will look like the following:

As you can see, all of the cells are currently empty. Based on the MVC design pattern, you have completed the implementation of the views (collection view section header and collection view) and the controller (ExploreViewController). Now, you will add model objects that will provide the data to be displayed.

In this section, you will add a property list, ExploreData.plist, to your project, which contains the name and the image filename for each cuisine.

Next, you will create a model object, ExploreItem, which will be a structure with two properties. One property will be used to store image filenames, and the other will be used to store cuisine names. After that, you will create a data manager class, ExploreDataManager, which will load the data from ExploreData.plist, put it into an array of ExploreItem instances and provide the array to ExploreViewController. Finally, you will modify ExploreViewController so it can provide data for the collection view to display.

Let's add ExploreData.plist to your project now and see how it stores cuisine data.

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

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