Objective-c instance variable access level, objective-c instance
In C # and JAVA, both method and variable have strict access level control, so the access level is rarely used in object-c, the reason may be that there is no access-level syntax on the method. There is no strength to control variables alone. Next we will discuss the access level of instance variables. When the instance variable is declared in the class, it is protected by default. Unlike C ++ or C #, java declares private by default. This is confusing for developers who develop in a multi-language environment.
The following describes the access level of instance variables:
| Protection level |
Complier directive |
Desciption |
| Privete |
@ Private |
Use the method declared inside the class |
| Protected |
@ Protected |
Used inside the class and subclass |
| Public |
@ Public |
Use any classes and Methods |
| Package |
@ Package |
Used in any part of the package. Currently, it is only applicable to 64-bit systems. |
Explicit and implicit Protection
Because protected is the default access level, and you can explicitly declare it.
@interface Player:NSObject{//this is a protected instance varible that implicit declareint m_playerExperience;}@interface Player:NSObject{//this is a protected instance varible that explicit declare@prootected int m_playerExperience;}
There is no difference between the two methods. However, the best practice is to explicitly write the access level, And you know its default access level instantly.