How to access @public instance variable from another class in Objective-C?

前端 未结 3 1812
-上瘾入骨i
-上瘾入骨i 2020-12-09 10:45

I know it\'s possible to define public instance variable with @public keyword. However, Objective-C syntax does not allow accessing other class\' variable. What features sho

3条回答
  •  离开以前
    2020-12-09 11:43

    You are supposed to write accessor methods to do that. Object-oriented design implies that a class shouldn't care about internal structure of objects of another class.

    That said, id is just a pointer, so you can do obj->ivar, provided you know what you're doing and there is no way to write a proper accessor method.

提交回复
热议问题