How do I mark designated superclass initializers as "invalid" in Objective-C?

From Adapting a Modern Objective-C Document :

If a class provides one or more designated initializers, it must implement all the assigned initializers of its superclass.

This means that if I have a subclass of NSObject that has its own designated initializer, let's say

 - (instancetype)initWithImage:(UIImage*)image NS_DESIGNATED_INITALIZER; 

then I also need to provide an implementation of NSObjects -init . What to do to mark -init initializer as "invalid", i.e. No one should call it, but use -initWithImage: instead? What is the best practice here?

Edit

I tried the methods 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 superclass initializer.

When I try to use other methods, i.e. raising an exception or -doesNotRecognizeSelector: inside -init , I get an error message indicating that I need to call one of my designated initializers.

+5
source share

All Articles