Category is a great concept. You can use a category to add new methods to any class, including those you do notSource code.
This is very convenient.
To add a new method to a class, we usually create a subclass.
However, subclass is sometimes inconvenient. You may not be able to create a subclass object. You may use the framework and toolkit, so
The object of the new class cannot be processed.
CATEGORY declaration:
@ Interface uiimage (imagetransform)
-(Uiimage *) transformtosize :( nssize *) Size
@ End
The existing class is located behind the @ interface keyword, followed by a new name in parentheses.
The class name is arbitrary. This name does not actually work. It is just a identifier. Of course it has practical significance
Can specify the role of this class.
CATEGORY limitations
1. Unable to add instance variables to the class
2. Name Conflict. When the name of a method in a category conflicts with the name of a method in an existing class, the method in the category has a higher
Priority. Generally, a prefix is added to a category to prevent name conflicts.
Category
1. Distribute the implementation of categories to multiple different files or different frameworks.
2. Create a forward reference to a private method. (In this case, the category name is usually null or privatemethods)
3. Add informal protocols to objects.