1. To force an object to hide its data, the compiler restricts the scope of the instance variable to limit its visibility in the program.
But to provide flexibility, Apple also lets developers display the set range (four choices).
2. The four compiler directives are as follows:
@private
An instance variable can only be accessed by the class that declares it.
@protected
An instance variable can be declared with its class and subclass, and all instance variables that do not display the specified range are @protected.
@public
Instance variables can be accessed from anywhere.
@packge
With the modern runtime, a @package instance variable is actually @public in the implementation of this class's executable image, but outside is @private.
The @package in OC is similar to the private_extern of variables and functions in C language. Any use of this instance variable outside the mirroring of the implementation class will cause link error to be thrown.
This type is most commonly used for instance variables of framework classes, too restrictive using @private, and too open with @protected or @public.
iOS Basics-instance variables four types of scopes