ObjectiveC accessing base class properties in subclass?
I am new to Object开发者_运维问答iveC and I have following inheritance.
@interface CGameEntity : NSObject {
b2Body *entityBody;
}
@property(nonatomic,retain) CCSprite *entitySprite;
-(id)initEntity:(CCNode*)parentNode :(b2World*)world;
@end
implementation :
@implementation CGameEntity
@synthesize entitySprite=entitySprite;
.
.
.
@end
And extended class is as follows :
@interface CPlanet : CGameEntity {
}
@end
implementation is as follows:
@implementation CPlanet
-(id)initEntity:(CCNode*)parentNode :(b2World*)world
{
if((self = [super init]))
{
//cannot access "entitySprite" ????
entitySprite=[CCSprite spriteWithFile:@"planet.png"];
}
return self;
}
@end
In the extended class I cannot access the property "entitySprite". How can I access properties of the base class ?
Thank you
First of all, replace ...
@synthesize entitySprite=entitySprite;
By ...
@synthesize entitySprite;
Then, replace this line ...
entitySprite=[CCSprite spriteWithFile:@"planet.png"];
By this ...
self.entitySprite = [CCSprite spriteWithFile:@"planet.png"];
This will work =)!
精彩评论