I am debugging a fragment of a sample tutorial and am confused about redefining setters.
I declare and redefine, as shown below:
// // PolygonShape.h // @interface PolygonShape : NSObject { int numberOfSides; } @property int numberOfSides; // // PolygonShape.m // @synthesize numberOfSides; // custom setter. - (void) setnumberOfSides:(int) i { if ((i > minimumNumberOfSides) && (i <= maximumNumberOfSides)) numberOfSides = i; else NSLog (@"Number of sides outside limits:\n You entered %d, limits are min.:%d, max.:%d", i, minimumNumberOfSides+1, maximumNumberOfSides); } // // main.m // poly = [[PolygonShape alloc] init]; poly.numberOfSides = 2; [poly setnumberOfSides:2];
So, my supposed thought is that since I am βredefiningβ the synthesized setter for numberOfSides , then poly.numberOfSides = 2; would call my function (void) setnumberOfSides:(int) i . But instead, the only way to call this function is when I explicitly do [poly setnumberOfSides:2];
I do not understand. What is the point then override?
Or rather, what am I doing wrong ?;)
source share