Access permissions for member variables
The member variables in OBJECTIVE-C have the following three properties
- Public (external and sub-class accessible)
- Protected (sub-class accessible, externally inaccessible)
- Private (external and sub-class inaccessible)
By default, the protected property
Example: Class A has 3 properties, Class B is a subclass of Class A, and the main function is external to class A.
A.h
@interface a:nsobject{@public int Publicvar; @protected int Protectedvar; @private int Privatevar;} @end
Main.m
int Main (intconstChar * argv[]) { @autoreleasepool { *a = [[A alloc] init]; A1; // OK 2; // Error Compilation But 3; // Error Compilation But } return0;}
B.m
@implementation B-(void) f{ *b = [[[B alloc] init]; b1; // OK 2; // OK 3; // Error Compilation But }@end
Note that the way you visit here is "--" instead of "." Oh oh oh oh
OBJECTIVE-C member variables