Day10 oc CategoryCategory

ocClassificationCategory

Function: extend the method to the class without modifying the original class

Notice:

1. Classification can only add methods, not member variables. If you want to add variables, consider using inheritance

2. Member variables of the original class can be accessed in the implementation of the classification method 

3. Re-implementing the method in the original class by classification will overwrite the original method and cause the original method to fail (not recommended)

4. The same method of multiple classification implementation classes will be viewed in the project->build phases->compile sources according to the compilation order.

  • Create a new file, select oc category under cocoa, and fill in the category to be expanded in category on
@interface class name (class name)
@end
@implementation class name (category name)
@end
  •  Add classification to the class that comes with the system

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939141&siteId=291194637