Part-2: Understanding First iPhone Application

Understanding First iPhone Application

In one of our previous articles, we were discussing about the contents in an simple iPhone Application; now we will discuss about few more files like ViewController.swift, there usages and methods contained.

ViewController is a file which helps in interaction with the views, how to design a view and interaction with the controllers can be viewed in the article from this link.

ViewController Methods:

As soon as we create a new class file sub class of UIViewController there are 2 default methods, which are already mentioned in the file.

  • viewDidLoad, when ever a ViewController is initiated; then this is the first function which gets executed, this method is executed only once whenever the ViewController class is being initiated.

 

iOS Tutorials: Understanding viewDidLoad
Understanding viewDidLoad
  • didReceiveMemoryWarning, whenever there is case like application is leaking memory or may be application is trying to access some extra memory which is more than the allocated memory buffer size from OS, the this method tells us about the warning.

 

iOS Tutorials: Understanding didReceiveMemoryWarning
Understanding didReceiveMemoryWarning

Note:Apart from these 2 functions, there are still 3 functions, which should be handled as per the requirements.

  • viewWillAppear, this method is called before the ViewControllers view about to be added into the view hierarchy, we can add our custom functionalities with displaying a view.

 

iOS Tutorials: Understanding viewWillAppear
Understanding viewWillAppear

Note: If another view controller inside of a popover presents a view controller, this method is not invoked on the presenting view controller after the presented controller is dismissed.

  • viewDidAppear, once the view is shown the any additional tasks needed to be performed can be handled here.

 

iOS Tutorials: Understanding viewDidAppear
Understanding viewDidAppear

Note: If another view controller inside of a popover presents a view controller, this method is not invoked on the presenting view controller after the presented controller is dismissed.

  • viewDidDisappear, any task associated with dismissing or hiding the view needs to be taken care here.

 

iOS Tutorials: Understanding viewDidDisappear
Understanding viewDidDisappear

Note: Please refer our next article for more details on the other files, please view the article from the link here.

We hope you are done with creating your first iPhone Application, you can download the project from the link here.

Author: Chandra.rao

iOS Developer. #Life of an developer.... Learn New technology, Code, Learn New Technology, Code, Death.