-2

My concern is the following,

If I create a Class with some method and inherit it then which methods are called lifecycle methods.

Are all overridable methods lifecycle methods? And in which category does it fall e.g OOPS ,OOAD

Example:- In iOS viewDidLoad is a lifecycle method but didReceiveMemoryWarning is not. If it is not called a lifecycle method , is it called a overridable method?

Som Bhattacharyya
  • 3,972
  • 35
  • 54
Sudhir
  • 127
  • 1
  • 12
  • 1
    The lifecycle methods of the `UIViewController` class are illustrated in the answers to [this question](http://stackoverflow.com/questions/5562938/looking-to-understand-the-ios-uiviewcontroller-lifecycle). – trojanfoe Apr 16 '16 at 09:38
  • But my concern is why `didReceiveMemoryWarning` is not called `lifecycle` methods – Sudhir Apr 16 '16 at 09:50
  • 3
    Because it not part of the normal flow of method calls; it's only used in exceptional circumstances. I think you are getting concerned for no reason; just override what you need without worrying about their classification as lifecycle or not. – trojanfoe Apr 16 '16 at 09:51
  • So `didReceiveMemoryWarning` is called overridable method not lifecycle method. – Sudhir Apr 16 '16 at 10:06
  • 2
    So what? Just get coding already! :D – trojanfoe Apr 16 '16 at 10:08
  • In Objective-C, all methods are overridable. This is a fundamental part of the programming language. Whether a method is considered a "life cycle" method or not is purely based on the semantics of the class and it has nothing do with the programming language or any design pattern. – rmaddy Apr 16 '16 at 14:31

2 Answers2

0

Methods don't have type like life cycle method or overridable method etc. UIViewController have it's own life cycle as per it's behavior that it is load or it appear etc.

And overriding is concept of inheritance. So there is no standard type like life cycle or overridable. Methods which are called from initialization of viewController to Disappearance, comes under lifecycle of viewcontroller.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • Are `lifecycle` methods come under any `design pattern`. Or there is any `design pattern` for `lifecycle` methods – Sudhir Apr 16 '16 at 11:31
  • there is nothing like life cycle method. UIViewcontroller have it's lifecycle in wich some methods are used like viewdidload etc. that's it. – Ketan Parmar Apr 16 '16 at 11:39
  • We define `viewdidload in` our `viewcontroller` means we are overriding it. so don't confuse in this kind of meaningless query. :) – Ketan Parmar Apr 16 '16 at 11:42
0

We use override when we want to add some features to our method from super class. If you create a class and implement UIViewcontroller as superclass.UIViewController has predefine method such as viewDidload, viewWillAppear,viewDidDisapear and others. If you want to add some features to superclass methods you should use override prefix. Override is used when you implement method of superclass and add your code. For example

class Student{

   func address(){
    var add1 = "drn"
   }

   func phoneNumber(){
    var no = 9806569690
   }
 }

//create another class and add student as superclass

 class Classroom: Student{

  //here address is method from      superclass student so i am using override prefix

   override func address(){
    var add2 = "ktm"
   }
 }

Actuctually i am typing from mobile phone. So i could not give you good example.