What describes @property(…) best? What's that actually good for?

前端 未结 2 1966
陌清茗
陌清茗 2020-12-22 12:56

All I think to know is, that it marks a property \"public\". And it creates setters and getters automatically. But when I don\'t have that, are my properties private?

<
相关标签:
2条回答
  • 2020-12-22 13:04

    @property () type prop_name is just a signal to compiler to create two methods:

    -(type) propName;

    and

    -(void) setPropName; // Not created for readonly properties

    In objective-C all methods are public. Let is why all properties are public too

    0 讨论(0)
  • 2020-12-22 13:30

    My understanding is that the @ infront of property makes it a compiler directive. It tells the compiler to do things. In this case it creates tells the compiler how to create the getter and setter methods for the member variable. You could do this manually of course, but this is there so that the compiler can do it for you.

    0 讨论(0)
提交回复
热议问题