Like in a sample code for XML parsing I encountered a comment:
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
Can somebody tell me the difference between protocol’s delegate method and delegate in general?
A protocol is like an interface. If you come from JAVA or C# you have already seen this in action. It’s just a list of methods without implementation. A class can (or not) conforms to a specific protocol. A class has to implement methods that are marked as required. Those that are optionals could not be implemented.
Delegation, instead, is a pattern that creates a relationships between two different objects. One of them, say A, is assisted by the second, say B. In other words, B does something for A.
The relationships between the two is that delegate methods (for a specific class) are listed in protocols. Here the term delegate protocol.
Why delegation is important? At some point of your application lifecyle, if a class send a message to its delegate (this it is not nil) and it has implemented a specific method (it can respond to that selector), the message is received by its delegate. At this point the control is captured by the delegate that performs some calculation and maybe can return some result.
Hope it helps.