I am trying to understand what is difference between initializing a subclass using [super init]
vs [SuperClassType classMethod]
. Below are the code examples:
-(instancetype)initWithAPPImageName:(NSString *)appImageName {
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"character"];
self = (AppNode *)[super initWithTexture:[atlas textureNamed: appImageName]];
if(self)
{
self.name = @"appNode";
if([self isKindOfClass:[AppNode class]])
{
self.position = [self GetPosition];
}
}
return self;
}
Here it works as expected. self
is kind of AppNode
, but below, it always returns SKSpriteNode
even though casting. What is different?
-(instancetype)initWithAPPImageName:(NSString *)appImageName {
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"character"];
self = (AppNode *)[SKSpriteNode spriteNodeWithTexture:[atlas textureNamed:appImageName]];
if(self)
{
self.name = @"appNode";
if([self isKindOfClass:[AppNode class]])
{
self.position = [self GetPosition];
}
}
return self;
}