From the Adapting Modern Objective-C document:
If a class provides one or more designated initializers, it must implement all of the designated initializers of its superclass.
That means if I have a subclass of NSObject
that has its own designated initializer, say
- (instancetype)initWithImage:(UIImage*)image NS_DESIGNATED_INITALIZER;
then I also need to provide an implementation of NSObjects -init
. What should I do to mark the -init
initializer as "invalid", i.e., nobody should call it but use -initWithImage:
instead? What's best practice here?
Edit
I tried the techniques described here.
However, when I mark the superclass -init
method as unavailable
in the interface, the compiler still tells me that I need to overwrite the initializer of the superclass.
When I try the other techniques, i.e., raising an exception or calling -doesNotRecognizeSelector:
inside of -init
, I get an error stating that I need to call one of my designated initializers.