문제

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

I had considered that separate structures were being generated in some way like this:

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

=> something along the lines of

struct Class_Foo_Protected {
  int bar;
};

struct Class_Foo_Private {
  int baz;
};

struct Class_Foo_Public {
  int qux;
};

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

도움이 되었습니까?

해결책

Those modifiers don’t change anything about the memory layout of your class. The compiler itself remembers which ivar is public, protected or private and emits errors if you try to access them from somewhere inappropriate. This is all done before any code is generated and doesn’t affect the generated code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top