Why is this ivar needed by @protected if @protected is the default?

@interface AClass : SomeType { @protected NSMutableArray* amINotAlreadyProtected; //? } 

Why is @protected needed if @protected is the default? This code was written by a very experienced programmer, but I omit the specifier myself.

+4
source share
2 answers

The @protected keyword is not needed as this is the default behavior.

However, some programmers tend to use it anyway if the less experienced programmer comes later and doesn't know it. You can also mention that it improves the readability of the code if there are some variables that are protected and other private or public.

+5
source

From the age when you can see:

 @interface Foo:Bar { @private … ivars … @protected … ivars … } … @end 

That is, while @protected is the default, you will need to use it if you switched to one of the other options and would like to go back. And, yes, there were reasons (often bad) to ensure that the ivar declaration order was maintained from release to release.

In addition, including the default keyword for the case, ensures that pedal gray beards (like me) can be clearly seen in their ads.

However, modern add-ons such as @property mean that such frauds are no longer needed.

+2
source

Source: https://habr.com/ru/post/1486907/


All Articles