• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
New error “Method override for the designated initializer of the superclass ‘-init’ not found”
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
      • From: Kyle Sluder <email@hidden>
    • Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
      • From: Sean McBride <email@hidden>
    • Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Is the f***ing NDA back, or why is no one talking about new stuff?
  • Next by Date: Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
  • Previous by thread: Re: Is the f***ing NDA back, or why is no one talking about new stuff?
  • Next by thread: Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
  • Index(es):
    • Date
    • Thread