iOS: Three ways to pass data from Model to Controller

Adopting MVC in iOS Project

Stan Ostrovskiy
7 min readOct 1, 2016
Image credit: Stanford University CS193P, Fall-2010

If you are an iOS developer, or a software developer in general, you definitely solve this problem in almost every project: how to pass data from the Model to Controller.

This assumes, of course, that you are using MVC or MVVM pattern in your project. If all of your code for requesting, receiving, and parsing data, along with updating the UI is located within a single UIViewController subclass, you should probably adopt one of the iOS Architecture Patterns first.

I will describe three basic ways of passing the data back to your Controller:

  1. Using Callbacks
  2. Using Delegation
  3. Using Notifications

We will go through each of these three concepts in details, following my example step-by-step. By the end of this tutorial you will able to choose which one is the best fit for your project.

At the beginning, we will create a basic project that has ViewController and DataModel classes. At this step, it doesn’t matter what your data source is. It could be a local JSON file, a local image saved in the app directory, Core Data, or a HTTP response. In any case, once you receive data in your Data Model, you need a way to pass it to your View…

--

--