views:

157

answers:

1

Hi,

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.

+2  A: 

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;
KennyTM
Thank 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.
George
Actually, "isPaused" is the correct naming convention in this case.http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html#//apple_ref/doc/uid/20001282-1004202-BCIGGFCC
JeremyP
@Jeremy: `-isPaused` as a getter is fine, but I'm talking about the property name, like [`.playing` (`-isPlaying`, `-setPlaying:`)](http://developer.apple.com/iphone/library/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008067-CH1-SW1).
KennyTM
I'd say that naming convention applies to properties too because properties are really just accessors. The same considerations should apply.
JeremyP
+1 for Jeremy for sharing the official documentation link about naming conventions.
Krishnan