且构网

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

添加 getter 会使使用下划线的语法不正确

更新时间:2023-11-07 23:12:10

一个属性没有自动合成如果您为该属性实现 setter 和 getter 方法,那么您必须明确地合成它:

A property is not automatically synthesized if you implement both setter and getter method for that property, so you have to synthesize it explicitly:

@synthesize foo = _foo;

(或显式添加实例变量_foo.)

(or add the instance variable _foo explicitly.)

同样适用于为只读属性实现 getter 方法的情况.

The same applies if you implement the getter method for a read-only property.

(如果你为一个属性实现了所有必要的访问器方法,那么编译器不再假设此属性必须由实例备份变量.)

(If you implement all necessary accessor methods for a property then the compiler does not assume anymore that this property is necessarily backed up by an instance variable.)