Protocols in objective-C are similar to common interfaces and are implemented in classes as defined in protocols.
@ Protocol myfirstprotocol
-(Void) myfirstprotocolmethod;
@ End
In iPhone OS, protocols are usually used to implement the delegate object ). A delegate object is generally used to define its own behavior or action, that is, to call its own defined method, but does not implement this method by itself, and delegates other classes to implement this method.
The uiapplication class is a typical example. The uiapplication class defines the action or action that an application should have. Instead of forcing your uiapplication subclass to accept the status messages of the current application and handle them accordingly. The uiapplication class transmits these messages to its delegate objects by calling special methods. By implementing the protocol named uiapplicationdelegate, this delegate object can receive and process the status messages of the current application. For example, important messages such as memory errors and application interruptions.
The following is a helloworld code:
Main. m
# Import int main (INT argc, char * argv []) {ngutoreleasepool * Pool = [[ngutoreleasepool alloc] init]; int retval = uiapplicationmain (argc, argv, nil, nil); [pool release]; return retval ;}