How to override @synthesized getters?

IphoneObjective CIos

Iphone Problem Overview


how to override a property synthesized getter?

Iphone Solutions


Solution 1 - Iphone

Just implement the method manually, for example:

- (BOOL)myBoolProperty
{
    // do something else
    ...
    return myBoolProperty;
}

The compiler will then not generate a getter method.

Solution 2 - Iphone

Inside of your property definition you can specify getter and setter methods as follows:

@property (nonatomic, retain, getter = getterMethodName, setter = setterMethodName) NSString *someString;

You can specify the getter only, the setter only, or both.

Solution 3 - Iphone

Just implement your own getter and the compiler will not generate one. The same goes for setter.

For example:

@property float value;

is equivalent to:

- (float)value;
- (void)setValue:(float)newValue;

Solution 4 - Iphone

I just want to add, I was not able to override BOOL property with getter/setter, until I add this :

@synthesize myBoolProperty = _myBoolProperty;

so the complete code is :

in header file :

@property  BOOL myBoolProperty;

in implementation file :

@synthesize myBoolProperty = _myBoolProperty;


-(void)setMyBoolProperty:(BOOL) myBoolPropertyNewValue
{
    _myBoolProperty = myBoolPropertyNewValue;
}

-(BOOL) myBoolProperty
{
    return _myBoolProperty;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSimone D'AmicoView Question on Stackoverflow
Solution 1 - IphoneOle BegemannView Answer on Stackoverflow
Solution 2 - IphonediadyneView Answer on Stackoverflow
Solution 3 - IphonestefanBView Answer on Stackoverflow
Solution 4 - Iphoneuser1105951View Answer on Stackoverflow