Objective-C category

Source: Internet
Author: User

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.

Related Article

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.