The difference between @private, @protected and @public

Source: Internet
Author: User

The difference between @private, @protected and @public

Diagram between classes

@private can only be used in declared classes, and its subclasses are not able to use instance variables declared with @private

@protected can only be used in declared classes, but its subclasses have the qualification to declare variables using @protected

@public can be used globally, a property that has a global property

The instance variable actually supports KVO, if you write the Setter,getter method for the instance variable

related source

#import <UIKit/UIKit.h>@interface  titleview:uiview {@private     int        _count;    // can only be used    in the current class @protected     nsstring  *_title;    // the current class and subclass can use the    @public     nsstring  //  can be used anywhere } @property (Nonatomic, Strong) NSString   *info; @end
#import "TitleView.h"@implementationTitleview-(Instancetype) initWithFrame: (CGRect) frame { self=[Super Initwithframe:frame]; if(self) {_count=4; _title=@"Title"; _subtitle=@"SubTitle"; }        returnSelf ;}@end
#import " TitleView.h " // Moretitleview inherited from Titleview @interface Moretitleview:titleview @end
#import " MoreTitleView.h " @implementation Moretitleview- (Instancetype) initWithFrame: (CGRect) Frame {        = [Super Initwithframe:frame] ;     if (self) {            }        return to self ;} @end

Instant no write Setter,getter method, but also can use Kvo oh, just need to manually trigger the

The difference between @private, @protected and @public

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.