Objective-C central agreement and Delegation

Source: Internet
Author: User

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 ;}
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.