New error “Method override for the designated initializer of the superclass ‘-init’ not found”
New error “Method override for the designated initializer of the superclass ‘-init’ not found”
- Subject: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
- From: Jens Alfke <email@hidden>
- Date: Tue, 09 Jun 2015 13:40:27 -0700
I’m getting a couple of odd new compile errors with Xcode 7. These are in classes that subclass NSObject and add an initializer that’s declared as a designated initializer, but do not implement -init because it’s not valid to initialize them without parameters. The new error says “Method override for the designated initializer of the superclass ‘-init’ not found”.
@interface Flump : NSObject - (instancetype) initWithString: (NSString*)str NS_DESIGNATED_INITIALIZER; @end
@implementation Flump // <- error reported on this line - (instancetype)initWithString: (NSString*)str { self = [super init]; if (self) { //... } return self; } @end
I suppose the error points out that someone initializing a Flump with -init would call the inherited -init from NSObject without any Flump-specific initialization occurring. Which seems sort of valid. So to fix the error I added an override of -init:
- (instancetype) init { @throw [NSException exceptionWithName: NSInternalInconsistencyException reason: @"Flump cannot be initialized with -init" userInfo: nil]; }
But this didn’t fix it. The new -init method gets an error “Convenience initializer missing a ‘self’ call to another initializer”. The only way to get rid of this error is to add a call to -initWithString … but there’s no valid parameter I can pass because the caller didn’t provide a string. Nor can I put this -init call after the throw, because then the compiler complains that it’s unreachable.
It seems as though whoever designed this hadn’t thought through the case where a subclass wants to _get rid of_ a superclass’s designated initializer, i.e. make it illegal to call it.
—Jens |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden