- In OC, we use protocols and classifications to achieve multiple inheritance effects.
- A protocol can only declare methods, not any instance variables.
- 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.