Τετάρτη, 28 Μαρτίου 2012

Delegate - Delegation - Why the first class in iOS projects ends in AppDelegate?

#source: The Big Nerd Ranch Guide - Objective C
___________________________________________
Lets say we create a new iOS project with name XXF. 

It creates automatically the XXFAppDelegate. During the phase of the first launch, an instance of UIApplication is created to control your applications state and act as liaison to the operating system.

 An instance of XXFAppDelegate is also created and set the delegate of the UIApplication instance (which explains the name "app delegate"").



From Documentation
___________________________________________

Delegation is a mechanism used to avoid subclassing complex UIKit objects, such as the UIApplication object. Instead of subclassing and overriding methods in a complex object, you use that object unmodified and put your custom code inside a delegate object. As interesting events occur, the complex object sends messages to your delegate object. You can use these hooks to execute your custom code and implement the behavior you need.
Important: The delegate design pattern is intended to save you time and effort when creating applications and is therefore a very important pattern to understand. For an overview of the key design patterns used by iOS applications, see “Fundamental Design Patterns.” For a more detailed description of delegation and other UIKit design patterns, see Cocoa Fundamentals Guide






 From dictionary: 
Delegate n. : a person sent or authorized to represent others, in particular an elected representative sent to a conference.


Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου