@public, @private, @protected (objc)

ref – http://stackoverflow.com/questions/844658/what-does-private-mean-in-objective-c

The @public, @protected, @private are called accessor modifiers. They provide access visibility to the instance variable.

So we declare 3 iVar using @public, @protected, @private.

We then declare a child class, and declare MyFirstClass as a parent class.

The basics are laid out here.

  • @public iVars CAN be accessed by the child class
  • @protected iVars CAN be accessed by the child class
  • @private iVars CANNOT BE accessed by the child class

Since we do not provide any accessor methods via properties, the instance varaibles are not accessed via the dot notation (.)

Rather, they are accessed through the arrow ( -> ).

enforce the use of accessors

Say a developer writes a class, then write properties and accessors. However, what if some other developer goes

xcode 4.x+ automatically puts @private in the template for an object. Thus, you don’t have to worry about other people accessing your instance variable with the arrow and modifying unexpectedly.

The only way to modify the instance variables, is through your property methods.