What Does "Delegate" Mean in Xcode?
You can use the Xcode integrated development environment from Apple to program iPhone, iPod touch and iPad apps in the Objective-C and Cocoa programming languages. Cocoa is the application programming interface, which lets you connect to iPhone, iPod touch and iPad services such as a map or camera. A delegate is a helper class in Cocoa that enables another object to notify it when certain events happen.
-
Role of Delegate
-
The delegate receives messages from a host object that contains a pointer reference to the delegate. The object sends messages to the delegate when it needs its input for a task.
Why Delegates Needed
-
The object needs the delegate because the object can only accomplish a generic task, so it needs the delegate to accomplish a more specific task.
-
How Delegation Works
-
The object notifies the delegate when the object needs its input for a particular task. The delegate provides specific behavior at various points in the task.
Delegation Design Pattern
-
Delegation is common in Cocoa. It is best practice to use delegation rather than subclassing a class.
-
References
Resources
- Photo Credit Justin Sullivan/Getty Images News/Getty Images