@property setter for BOOL
I'm having problems setting a BOOL using @property
and @synthesize
.
I'm using @property BOOL isPaused;
And I can get it by using [myObject isPaused];
but I cannot manage to set it. I'd like to use [myObject setPaused: NO];
. I also tried @pr开发者_如何学Pythonoperty (setter=setPaused) BOOL isPaused;
but if I'm not mistaking, then I need to write that setter myself.
Why not use the dot notation?
myObject.isPaused = YES;
return myObject.isPaused;
If your property is declared as @property BOOL isPaused
, then the setter is always called as
[myObject setIsPaused:YES];
To rename the setter you must provide the full signature including the colons:
@property(setter=setPaused:) BOOL isPaused;
...
[myObject setPaused:YES];
BTW, the naming convention is not to include verbs in a property.
@property(getter=isPaused) BOOL paused;
精彩评论