Delegates are mah mah mah (adult Peanut character sound) 
When I started objective-c, coming from VB.net and C#, I couldn’t wrap my pea brain around delegates based on the information I found.
Wikipedia says:
In software engineering, the delegation pattern is a design pattern in object-oriented programming where an object, instead of performing one of its stated tasks, delegates that task to an associated helper object. There is an Inversion of Responsibility in which a helper object, known as a delegate, is given the responsibility to execute a task for the delegator. The delegation pattern is one of the fundamental abstraction patterns that underlie other software patterns such as composition (also referred to as aggregation), mixins and aspects.
YAWN. Could they make that description more verbose and boring?? Geez. No wonder people run screaming from development. It’s like a secret society of making things SO utterly boring and overly complex they chase away otherwise capable people.
Here is my own definition.
Erick says:
A delegate is when you give one class another class’ events.
Makes more sense to me.
So as an example; in iOS development, you want to have a UIViewController and you give it a UIActionSheetDelegate to it. You are just saying: “Hey, even though this guy is just a view, I want it to also have respond to UIAlert stuff.”
In your .h file, you tell it “I want this guy to respond to UIAction stuff…”
@interface MyHotViewController : UIViewController {
}
And in the .m file, you can put in the UIActionsheets event without XCode having an absolute conniption…
m.
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0){
//do your sweet action here
}
}
At least that’s how I understand it. Educate me if I’ve made this too simple.
Tweet