Wednesday, July 23, 2008

Protocol Objects?

Not again!!

Now Protocol Objects it seems this never stops. The objects created by protocols (seen earlier) just creates more mess since they are instances of Protocol Class!! Now who did that?!!

Special way of calling them:

Protocol *myXMLSupportProtocol = @protocol(MyXMLSupport);

Adopting protocols?

Yep, "A class is said to adopt a formal protocol if in its declaration it lists the protocol within angle brackets after the superclass name":

@interface ClassName : ItsSuperClass <>

2 or more would be comma-separated inside angle brackets. Categories do basically the same, just use the category declaration and still add the angle brackets with the protocol list

If a class adopts a Protocol the it conforms it. This said, check how it's done.

if ( ! [receiver conformsToProtocol:@protocol(MyXMLSupport)] ) {
// Object does not conform to MyXMLSupport protocol
// If you are expecting receiver to implement methods declared in the
// MyXMLSupport protocol, this is probably an error
}

Enough adopt and conform...let's move on.

No comments: