Geo*_*rge 3 boolean properties objective-c
我在使用@property和设置BOOL时遇到问题@synthesize.我正在使用@property BOOL isPaused;而且我可以通过使用获得它,[myObject isPaused];但我无法设置它.我想用[myObject setPaused: NO];.我也试过,@property (setter=setPaused) BOOL isPaused;但如果我没有误会,那么我需要自己写那个二传手.
为什么不使用点符号?
myObject.isPaused = YES;
return myObject.isPaused;
Run Code Online (Sandbox Code Playgroud)
如果您的属性声明为@property BOOL isPaused,则始终将setter称为
[myObject setIsPaused:YES];
Run Code Online (Sandbox Code Playgroud)
要重命名setter,您必须提供包括冒号的完整签名:
@property(setter=setPaused:) BOOL isPaused;
...
[myObject setPaused:YES];
Run Code Online (Sandbox Code Playgroud)
顺便说一句,命名约定不包括属性中的动词.
@property(getter=isPaused) BOOL paused;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11822 次 |
| 最近记录: |