• 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
Re: 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]

Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”


  • Subject: Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 10 Jun 2015 02:16:04 -0500

On Tue, Jun 9, 2015, at 03:40 PM, Jens Alfke wrote:
> 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.

You should be able to use the NS_UNAVAILABLE macro in your @interface to
"delete" -init from your subclass, and thus suppress the warning.

(You'll need to keep your asserting implementation of -init in case
someone manages to send that message regardless.)

--Kyle Sluder

 _______________________________________________
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: Jens Alfke <email@hidden>
    • Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
      • From: Sean McBride <email@hidden>
References: 
 >New error “Method override for the designated initializer of the superclass ‘-init’ not found” (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
  • Next by Date: Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
  • Previous by thread: Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
  • Next by thread: Re: New error “Method override for the designated initializer of the superclass ‘-init’ not found”
  • Index(es):
    • Date
    • Thread