-1

When we implement (id)initWithCoder:(NSCoder *)decoder method in NSObject class, we need to call [super **init**], but in UIView somehow we need to call [super **initWithCoder:decoder**]. Why is there such a difference? The question is not a duplicate because it concerns protocols conformance to NSCoder in this particular case. There can well be other classes' situation similar to the one specified in the question.

Nikita Vlasenko
  • 4,004
  • 7
  • 47
  • 87

1 Answers1

3

You should call [super initWithCoder:decoder]; for any class that subclasses a class that already conforms to the NSCoding protocol.

In the case of a class that directly extends NSObject then of course you can't call [super initWithCoder:decoder]; because NSObject doesn't conform to NSCoder and therefore doesn't have an initWithCoder: you can call from the subclass. So you must call some other init method.

In the case of a custom view extending UIView, you do call it because UIView conforms to NSCoding.

rmaddy
  • 314,917
  • 42
  • 532
  • 579