@interface AClass : SomeType {
@protected
NSMutableArray* amINotAlreadyProtected; //?
}
Why does this code need @protected
if @protected
is the default? This code was written by a very experienced programmer, but I would omit the specifier myself.
There is no need for the keyword
@protected
as it is the default behavior.However, some programmers tend to use it anyways incase a less experienced programmer comes along at a later date and doesn't know this. It can also be mentioned that it increase code readability incase there are some variables that are protected and other private or public.
It is from an age when you might see:
That is, while @protected is the default, you would need to use it if you had switched to one of the other variants and wanted to switch back. And, yes, there were reasons (often bad ones) to ensure that ivar declaration order was preserved from release to release.
Beyond that, including a keyword for the default case ensures that pedantic grey beards (like myself) can be exactly explicit in their declarations.
However, modern additions like
@property
mean that such shenanigans are no longer necessary.