Class category vs class Extension

Source: Internet
Author: User
1. extension is more like Anonymous category (class extensions are like Anonymous categories) 2. Category is more inclined to be written in an independent file, and then named "nsview + customadditions. h ", in the corresponding. block in the M file. Therefore, cagegory tends to be used to separate functions of classes and organize functional modules of classes. Extension is more inclined to write at the top of the. M file of the same class, and its implementation is placed in the implementation block of the class. Through this sentence, we feel that the private function for implementing the objc class adopts the class
Extension
3. Variables cannot be defined in category. Extension can define variables and properties as follows:
@interface MyClass : NSObject
- (float)value;
@end
@interface MyClass () {
    float value;
}
- (void)setValue:(float)newValue;
@end
@implementation MyClass
- (float)value {
    return value;
}
- (void)setValue:(float)newValue {
    value = newValue;
}
@end

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.