OC Sixth Day Note March 21, 2016 (Monday) a.m.

Source: Internet
Author: User

    1. In OC, we use protocols and classifications to achieve multiple inheritance effects.
    2. A protocol can only declare methods, not any instance variables.
    3. Declaration Agreement:

@protocal Protocolname<protocol,... >

@optional//selectable

@require//Required Default

@end

eg

1 @protocal rules<nsobject >23  45@interface ABC: NSObject <rules>67@end

Only method declarations in the protocol, no instance variables

Implements the implementation of the file in the class. The main function is invoked using the message mechanism.

4. Classification: Add a method to the original class, not an instance variable.

1 @interface nsstring (detail) 2 3 @end

The purpose of classification: The method of the original class is insufficient, the original type method name is too complex, not easy to understand and remember.

Classification is part of the original class.

The classification cannot have inheritance, but it can follow the protocol.

5. Other Features: Performselector

Argument of the function without arguments

-(ID) Performselector: (SEL) Aselector;

The argument of the function takes a parameter

-(ID) Performselector: (SEL) Aselector withobject: (ID)

Anobjectasparameter

The arguments of a function are passed up to two parameters

-(ID) Performselector: (SEL) Aselector withobject: (ID)

Anobjectasparameter Withobject: (ID) anotherobjectasparameter;

6. OC cannot declare static instance variables. You can declare a static global variable.

OC Sixth Day Note March 21, 2016 (Monday) a.m.

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.