@property setter for BOOL
11,876
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;
Author by
George
Updated on June 04, 2022Comments
-
George almost 2 years
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@property (setter=setPaused) BOOL isPaused;
but if I'm not mistaking, then I need to write that setter myself. -
George almost 14 yearsThank you. I tried the dot notation before but I'm not a big fan of it. I also couldn't get it to work somehow? Anyway, I forgot the capital 'I' in setIsPaused... And I didn't know you needed the colon in the setter= attribute.
-
JeremyP almost 14 yearsActually, "isPaused" is the correct naming convention in this case. developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/…
-
kennytm almost 14 years@Jeremy:
-isPaused
as a getter is fine, but I'm talking about the property name, like.playing
(-isPlaying
,-setPlaying:
). -
JeremyP almost 14 yearsI'd say that naming convention applies to properties too because properties are really just accessors. The same considerations should apply.
-
RK- over 13 years+1 for Jeremy for sharing the official documentation link about naming conventions.
-
Christian almost 10 yearsFor adjectives, you leave off the "is" from the property name: developer.apple.com/library/mac/DOCUMENTATION/Cocoa/Conceptual/…