Why do I need to write @synthesize when I provide getter and setter?

后端 未结 3 1850
别那么骄傲
别那么骄傲 2020-12-03 08:54

So the auto synthesize of properties is awesome. However, when you provide both a getter and a setter, you get an error.

@property (strong, nonatomic) NSArra         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 09:29

    When you provide both getter and setter, there is often just no need for an instance variable at all, i.e. when you just forward those messages or store data in other places.

    As soon as one of them is missing, the ivar is needed to synthesize that functionality.

    If I remember correctly, for readonly properties the analogue assumption holds as well.

提交回复
热议问题