Subclassing a Method Returning instancetype

526 views Asked by At

I have a custom class which is a subclass of SKSpriteNode. I am trying to override the spriteNodeWithColor:size: method which returns instancetype. I try this:

 -(instancetype)initWithColor:(UIColor *)color size:(CGSize)size{
     self.color = color;
     self.size = size;

     //do other setup stuff here
     return self;
}

but it crashes every time. Thanks in advance for your help

1

There are 1 answers

3
Marcelo On BEST ANSWER

You need to call super:

- (instancetype)initWithColor:(UIColor *)color size:(CGSize)size {
    self = [super initWithColor:color size:size];

    if (self) {
      // do other setup stuff here
    }

    return self;
}