I have two classes: Geometry and Circle. Circle is a subclass of Geometry.
Geometry has a synthesized property:
interface:
@interface Geometry : NSObject <drawProtocol, intersectionProtocol>
@property int geoLineWidth;
implementation:
@synthesize geoLineWidth;
Circle is a subclass of Geometry. The interface:
@interface Circle : Geometry
This code compiles, inside a method of Geometry, in Geometry.m
NSLog(@"%d", geoLineWidth);
This code does not compile, inside a method of Circle
NSBezierPath * thePath= [NSBezierPath bezierPath];
[thePath setLineWidth: geoLineWidth];
Use of undeclared identifier 'geoLineWidth'
However, this code compiles:
[thePath setLineWidth: [self geoLineWidth]];
Is this behavior intentional, or am I missing something ?
In the subclass, instead of accessing the instance variable directly, you must actually use the accessor.
Change this:
To this:
To get the compiler to recognize the instance variable, you’d need explicitly to declare it in the superclass header file.