The extension of OC classes is summarized as follows:
There are 4 in total:
1. subClass
Purpose: You can use class inheritance to add the variables and methods of the parent class.
Statement: In the. h file
@ Interface Student: Person
2. Category
Function: you can add a parent class, but cannot define variables. It is often used to extend the parent class without knowing the source code.
Syntax: In the. h and. m files, the file name is in the format of "parent class name + category name.
After @ interface @ implementation, "parent class name (category name )"
3. Extension
Purpose: Define private methods. You can hide methods that are not published. Mostly used to hide some intermediate steps.
Written in: implemented before @ implementation in the. m file
@ Interface Person () {NSString * _ age ;}
-(Void) aa;
@ End in this way, the private method is defined.
4. protocol
Purpose: implement methods similar to multiple inheritance. A class complies with multiple protocols. Statement: the Protocol only has. H files, and the method is defined. @ Required // required by default
-(Void) method1;
-(Void) method2;
@ Optional // optional
-(Void) method3;
Currently, we will continue to add more.