Objective-C use property and it's storage location. Difference?

前端 未结 2 1923
自闭症患者
自闭症患者 2021-01-27 05:21

What is the difference between property name and property storage location? I must use only property name or mm what is the point to use first or the second? Here is my example:

2条回答
  •  梦毁少年i
    2021-01-27 05:52

    self.carSpeed = speed; 
    

    This uses setter method

    Whereas,

    _carSpeed = speed;
    

    uses directly the ivar or property through the alias created.


    Using . notation gives you the facility to access them from outside the class and setters and getters are in public zone.

    Whereas, _carSpeed makes it local to the class. And more it is a old convention.

    Synthesized property and variable with underscore prefix: what does this mean?

提交回复
热议问题