Think of a delegate as an ordinary object that can perform some of the functions. For example, take the NSTableView delegate. You want to render a table cell as something on its own. My NSTableView delegate will send the message that he will now draw the cell, and the delegate already decides what to do with it (draw on the, do not touch at all, etc.). This is, roughly speaking, the method of obtaining and providing information about which NSTableView doesn't know anything.
Or an example of creating your own delegates. Imagine you have a class that performs a certain function. For some tasks he needs information from another class, which is now not known absolutely nothing, except that it exists. We can create a design view:
@interface Class1 {
id delegate;
}
\r
— (id)delegate;
— (void)setDelegate:(id)newDelegate;
\r
@implementation Class1
\r
— (id)delegate {
return delegate;
}
\r
— (void)setDelegate:(id)newDelegate {
delegate = newDelegate;
}
\r
As you can see, our delegate is just a pointer to any object. Well, provided the getter and setter. In order that the delegate has performed some action for us, somewhere within our Class1 we send a message of the form [delegate doSomeWork];
The object, which we have appointed the delegate for this class in turn receives the message and take some action.
In principle, and all. Simple enough.