Class extension, class category, Class-continuation category

Source: Internet
Author: User

Class extension

    • OBJECTIVE-C 2.0 adds the class extensions to solve two problems:
    1. Allows an object to have a private interface and can be validated by the compiler.
    2. Supports a public read-only, private writable property.
    • Extension is more like an anonymous category.

Class Category

    • The category is more likely to be written in a separate file, followed by the name "Nsview+customadditions.h", implemented in block blocks in the corresponding. m file. Therefore, Cagegory is more inclined to separate the functions of class, and to organize the function modules of classes.
    • Extension prefers to write at the top of the. m file of the same class, and its implementation is placed in the implementation block of that class.
    • such as the last Uiimage+display.h, is the system of the UIImage class supplement

Difference between Category and Class Extension?

    • A category is a A-methods to add-to-existing classes. They usually reside in files called "Class+categoryname.h", like "Nsview+customadditions.h" (and. m, of course).
    • A class extension is a category, except for 2 main differences:
      • The category has no name. It's declared like this:
      •   @interface   SomeClass () -(void  ) Anadditionalmethod; 
           @end  
      • The implementation of the extension must is in the main @implementation block of the file.
    • It ' s quite common to see a class extension at the top of a. m file declaring more methods on the class, that's then Impl Emented below in the main @implementation section of the class. This is a-to-declare "Pseudo-private" methods (pseudo-private in that they ' re isn't really private, just not externally Exposed).

Class-continuation category

Class-continuation category See "Effective OBJECTIVE-C 2.0" 27th

Class extension, class category, Class-continuation category

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.