Objective-C - readonly properties not synthesized with underscore ivar?

后端 未结 1 1782
闹比i
闹比i 2020-12-16 10:57

If I understand correctly, in Objective-C, properties are automatically synthesized with getters and setters, with the instance variable declared as the property name with a

相关标签:
1条回答
  • 2020-12-16 11:08

    A property is not automatically synthesized if you implement all required accessor methods (getter for a read-only property, getter + setter for a read-write property).

    Because you implement the getter method -(NSString *)myString for the read-only property, it is not auto-synthesized. If your getter needs an instance variable to backup the property value, you have to add the synthesize statement (as you did) or an instance variable.

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