iOS For Beginner

Model View Controller coding pattern

Generally we have different type of coding pattern and we choose coding pattern based on what type of apps we are developing.But the common coding pattern that is recommended for beginners is MVC Pattern.

What is MVC ?

MVC stands for Model View Controller, as mentioned earlier it is one of the coding pattern used for iOS app development.

In MVC single application is divided into three parts as:

● Model
● View
● Controller

The main purpose of MVC is “Re-usability” Where we can reuse the same model for different Views.Let’s see one by one.

Model

The model is nothing but Database which contains data, information, logic, or objects considered part of the layer of your iOS app. The model does not talk directly to a view, instead is made available to a controller which accesses it when needed. In iOS, a model is usually a subclass of NSObject or in the case of Core Data (an iOS framework that helps save data to a database locally on the device) NSManagedObject. We will explain each syntax in upcoming chapters.

The view displays information contained in the model.For example a view could display a list of names and numbers. Although the view does not obtain the information directly from the model.It uses the controller as a mediator which instruct it and what type of data to display in screen.In iOS most views subclass from UIView which provide the features for handling touch events and any interaction on screen and the common framework we have for iOS is UIKit framework. It contains classes to interface element like button,textfields etc. So like our example here the list of Contacts are displayed in screen.

View

Controller

Finally, the controller is responsible for accessing data from the model and displaying it on the view. The same controller can be used to intermediate between several views and models. The controller monitors user interaction with the view and communicates any changes to the model. In iOS, the controller is generally a subclass of UIViewController that manages a view, it is also responsible for responding to delegation messages and target­-actionmessages.

MVC Coding Pattern

So the above image clearly says that, every time when user did some action it first reaches to controller and the controller update to model. There is no direct connection between View and model as we mentioned earlier. After get the updates from controller,the model notify to controller what type of user action were performed and again controller update to View and it display on screen. This explains about the MVC Design pattern for iOS. Alternative way for MVC is MVVM and there are some other design patterns are available for iOS. They are:

You can check the other design patterns for iOS application and you can refer it through apple documentation for all Design patterns.

And here we are using the Xcode version 7.2.You can download this version from app store ( with apple acount id) .So you can get the xcode free from Apple download section.

We need to have Apple account in order to download it. If we don’t have it then create a new account, it’s free of cost. And when we download the xcode tool from another website like .dmg file it will not be reliable. After you login you must see the below screen.In that select the latest xcode 7.2.

Xcode

After that expand xcode 7.2.Then you can see that .dmg file of xcode. Click that to download.