Lesson 4 - Swift

MVC (Model, View, Controller)

The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components: the model, the view, and the controller.

Each of these components are built to handle specific development aspects of an application. MVC is one of the most frequently used industry-standard web development framework to create scalable and extensible projects.

Models

The objects that will be used to transport data.

Views

Responsible to handle all UI interactions.

Controllers

Responsible to handle all business code.

You can use the MVC Base project as reference for your personal project.

Calling a RESTful API

As a reference you can check the Sample App code.

  • Structuring calls

    • Create a simple and exclusive method to call the backend. On our example the function fetch

    • The fetch method receives as parameters an URL variable of the type URLRequest and two callbacks to be able to return values on success and fail scenarios.

  • Call backend

    • Implement the fetch method body code. On our example the code is

    • The fetch body method is a generic code to handle any call and delivery the data from the response object. We have to create a DataTask object using the Session object and also we have to implement the completitionHandler, because only on this way we can handle properly the response from backend.

  • Testing Class

Last updated