Home > DeveloperSection > Interviews > What is the use of Delegation in iOS?

Posted on    August-04-2015 12:33 AM

 iPhone iPhone  Ios  Objective C 
 1 Answer(s)
  569  View(s)
Rate this:

Felix Pickles
Felix Pickles

Total Post:3

Posted on    August-04-2015 12:33 AM

Delegation is a design pattern in which one object sends messages to another object—specified as its delegate—to ask for input or to notify it that an event is occurring. Delegation is often used as an alternative to class inheritance to extend the functionality of reusable objects. For example, before a window changes size, it asks its delegate whether the new size is ok. The delegate replies to the window, telling it that the suggested size is acceptable or suggesting a better size.

Delegate methods are typically grouped into a protocol. A protocol is basically just a list of methods. The delegate protocol specifies all the messages an object might send to its delegate. If a class conforms to (or adopts) a protocol, it guarantees that it implements the required methods of a protocol. (Protocols may also include optional methods), the application object tells its delegate that the main startup routines have finished by sending it theapplicationDidFinishLaunching: message. The delegate is then able to perform additional tasks if it wants.

Don't want to miss updates? Please click the below button!

Follow MindStick