How is @private implemented?

In Objective-C, I'm curious how access controls for instance variables such as @protected , @protected , etc. are @protected .

I believed that the individual structures are generated in some way as follows:

 @interface Foo { int bar; @private int baz; @public int qux; } 

=> something along the lines

 struct Class_Foo_Protected { int bar; }; struct Class_Foo_Private { int baz; }; struct Class_Foo_Public { int qux; }; 

But I really have no idea. Does anyone know how this was done?

+4
source share
1 answer

These modifiers do not change anything in the memory layout of your class. The compiler itself remembers which ivar is publicly available, protected, or private, and emits errors if you try to access them somewhere inappropriate. All this is done before the creation of any code and does not affect the generated code.

+7
source

All Articles