The Protocol (PROTOCOL) in Objective-c is similar to the commonly used interface, the method defined in the Protocol (Protocols), implemented in the class.
@protocol Myfirstprotocol
-(void) Myfirstprotocolmethod;
@end
In the iphone OS, Protocol (PROTOCOL) is commonly used to implement delegate objects (Delegate object). A delegate object (Delegate object) is typically used to define its own behavior or action, that is, to call itself to define a method, but not to implement the method itself, and to delegate other classes to implement the method.
The UIApplication class is a typical example. The UIApplication class defines the behavior or action that an application should have. Instead of forcing your uiapplication subclass to accept the status message for the current application and make the appropriate processing. The UIApplication class passes these messages to its delegate object by calling a special method. This delegate object, by implementing the Protocol named Uiapplicationdelegate (Protocol), can then accept the status message for the current application and make the appropriate processing. such as the memory error, the application is interrupted and other important messages.
Here is a HelloWorld code:
Main.m
#import
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = Uiapplicationmain (argc, argv, nil, nil);
[Pool release];
return retVal;
}