Category "Object-c" and extension categories

Source: Internet
Author: User
The dynamic characteristics of object-c allow the use of categories to add new methods to existing classes, and do not need to create subclasses, without accessing the source code of the original class. By using categories, you can dynamically add new methods to existing classes, and you can modularize the class definition into multiple related files.
Point:1, the definition class name must be a class that is not in the project, and the class name that is used when defining a category must be an existing class 2, defining a category must use () to contain the class name 3, the category is typically defined only by the classes method and the instance method, cannot add an instance variable (can be added by extension extension) 4, Do not overload another method, resulting in the original method is not available 5, according to the need can have more than one classification, classification will affect subclass 6, through the class for the specified class to add a new method, the new method can affect the subclass of the specified class, subclass can also inherit to this new method. 7. Use categories to invoke Private method 8, use categories to implement informal protocol 9, you can use categories to modular design of classes
@interface existing class (category name)-instance method + class method @end
Extended @interface already has class () {instance variable;}-class method; + instance method; @end

Category "Object-c" and extension categories

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.