Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is overriding a synthesize property in Objective-C Ok or bad?

Tags:

I have overridden a synthesized property because I wanted to add an NSAssert.

Is this OK to do (i.e override) or considered bad practice?

@synthesize someField;

-(NSString*)someField {
    NSAssert(someField != nil,@"someField");
    return someField;
}
like image 626
JARC Avatar asked Jun 25 '09 11:06

JARC


1 Answers

That is fine. From the documentation:

You use the @synthesize keyword to tell the compiler that it should synthesize the setter and/or getter methods for the property if you do not supply them within the @implementation block.

So if you provide them, then the compiler will use yours, irrespective of the @synthesize directive.

like image 64
Peter N Lewis Avatar answered Oct 12 '22 07:10

Peter N Lewis