Friend classes in Objective-C

前端 未结 2 1260
眼角桃花
眼角桃花 2020-12-08 21:45

Is there any way to create something like friend classes in Objective-C?

2条回答
  •  情话喂你
    2020-12-08 21:51

    There is no such thing as a friend class in ObjC.

    And to access a private variable of another class you don't even need to be declared as a friend. For example, you can use the runtime functions

    id the_private_ivar;
    object_getInstanceVariable(the_object, "_ivar_name", &the_private_ivar);
    

    to get the_object->_ivar_name, bypassing compiler checks.

提交回复
热议问题