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

前端 未结 3 1814
-上瘾入骨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:25

    You can access it like using -> (member by pointer) operator like you normally access members of a c-structure (note that you always have a pointer to an object in obj-c):

    ...
    @public
    int a;
    ...
    
    myObject->a = 1;
    

提交回复
热议问题