我在使用设置 BOOL 时遇到问题@property
and @synthesize
。
我在用着@property BOOL isPaused;
我可以通过使用得到它[myObject isPaused];
但我无法设置它。我想用[myObject setPaused: NO];
。我也尝试过@property (setter=setPaused) BOOL isPaused;
但如果我没有记错的话,那么我需要自己编写该设置器。
为什么不使用点符号?
myObject.isPaused = YES;
return myObject.isPaused;
如果您的财产被申报为@property BOOL isPaused
,那么 setter 总是被称为
[myObject setIsPaused:YES];
要重命名 setter,您必须提供完整的签名包括冒号:
@property(setter=setPaused:) BOOL isPaused;
...
[myObject setPaused:YES];
顺便说一句,命名约定是不要在属性中包含动词。
@property(getter=isPaused) BOOL paused;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)