Protocols and delegates in the Objective-c

Source: Internet
Author: User
Tags define

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;    
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.