且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

覆盖getter只需要@synthesize

更新时间:2023-02-21 11:54:39

否,如果您明确实现所有访问器方法(readwrite的getter和setter),则只需显式地合成(以获取合成的ivar).属性,仅是readonly属性的吸气剂).您已经为此readwrite属性编写了getter方法,但没有编写setter方法,因此ivar仍将为您合成.因此,就您的代码而言,您无需显式地@synthesize.

No, you only need to explicitly synthesize (to get the synthesized ivar) if you explicitly implement all of the accessor methods (both getter and setter for readwrite properties, just the getter for readonly properties). You've written the getter for this readwrite property, but not the setter, so the ivar will still be synthesized for you. Thus, as your code stands, you do not need to explicitly @synthesize.

如果将此属性设置为readonly,则实现getter将阻止ivar自动合成.同样,由于这是readwrite,因此,如果同时实现了getter和setter,则将需要综合ivar(如果需要).

If you made this property readonly, then implementing a getter would prevent your ivar from being automatically synthesized. Likewise, since this is readwrite, if you implemented both the getter and the setter, that would require you to synthesize the ivar (if you wanted one).