Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: Compiler error when overriding a superclass getter and trying to access ivar

Tags:

I'm working on building an iOS 6 app.

I have a class TDBeam which inherits from superclass TDWeapon.

The superclass TDWeapon declares a @property in the TDWeapon.h file:

@interface TDWeapon : UIView

@property (nonatomic) int damage;

@end

I do not explicitly @synthesize the property, as I'm letting Xcode automatically do so.

In the subclass TDBeam I override the getter in the TDBeam.m file:

#import "TDBeam.h"

@implementation TDBeam

- (int)damage {
    return _damage;
}

@end

Xcode auto-completes the getter method name, as expected. But when I attempt to reference the _damage instance variable (inherited from the superclass), I get a compiler error:

Use of undeclared identifier '_damage'

What am I doing wrong here? I've tried explicitly adding @synthesize, and changing the name of the _damage ivar, but the compiler doesn't "see" it or any other ivars from the superclass. I thought ivars were visible and accessible from subclasses?