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