What does “@private” mean in Objective-C?

后端 未结 3 1178
情话喂你
情话喂你 2020-11-28 01:11

What does @private mean in Objective-C?

3条回答
  •  抹茶落季
    2020-11-28 01:31

    It important to understand what it means when somebody says that you can't access a @private instance variable. The real story is that the compiler will give you an error if you attempt to access these variables in your source code. In previous versions of GCC and XCode, you would just get a warning instead of an error.

    Either way, at run time, all bets are off. These @private and @protected ivars can be accessed by an object of any class. These visibility modifiers just make it difficult to compile the source code into machine code that violates the intent of the visibility modifiers.

    Do not rely on ivar visibility modifiers for security! They provide none at all. They are strictly for compile-time enforcement of the class-builder's wishes.

提交回复
热议问题