17

I'm getting the compile error:

error: convenience initializer missing a 'self' call to another initializer [-Werror,-Wobjc-designated-initializers]

Compile-checked designated initializers might be a good thing, but if I don't want deal with that right now, how can I turn this off?

Clay Bridges
  • 11,602
  • 10
  • 68
  • 118

2 Answers2

36

Following on from Clay's answer..

Method 3

You might want to suppress the warning on one occurrence, not all of them:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype) initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        // do whatever I was doing....
    }
    return self;
}
#pragma clang diagnostic pop

EDIT: However, I've only actually used this once myself. I find it the same amount (or a little more) effort just to do it properly if it's a single case. So flag up your constructor with NS_DESIGNATED_INITIALIZER. And if it then complains about the init method not being overridden add an init method to your header with NS_UNAVAILABLE.

bandejapaisa
  • 26,576
  • 13
  • 94
  • 112
  • This is great @bandejapaisa, do you by chance have a list of where the error messages and their corresponding string like above are stored. Is there a lookup table somewhere? – Logan Oct 23 '15 at 21:05
  • Good question. Did a quick search and didn't find any list on clang website or documentation. Did find this though: http://nshipster.com/clang-diagnostics/ which has a link at the bottom of the article to a site with a list - although it doesn't contain this particular error, so it can't be a definitive list. – bandejapaisa Oct 26 '15 at 07:09
18

Method 1

In your project:

  1. Edit the build settings for your target (⌘-1, select project, or cf. Apple docs).
  2. Search for "Other warning flags". up in here, yo
  3. Add -Wno-objc-designated-initializers.

You can also do some combination of this and -Wobjc-designated-initializers on a per file basis or with clang diagnostic pushes and pops (cf. @bandejapaisa's "Method 3" answer below).

Method 2

This method allows you to switch back and forth between Xcode 5 & 6, and also provides you a reminder to fix the designated initializer stuff.

For iOS development, put this in your .pch (precompiled header) file:

#ifdef __IPHONE_8_0
    // suppress these errors until we are ready to handle them
    #pragma message "Ignoring designated initializer warnings"
    #pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#else
    // temporarily define an empty NS_DESIGNATED_INITIALIZER so we can use now,
    // will be ready for iOS8 SDK
    #define NS_DESIGNATED_INITIALIZER
#endif

The analog to __IPHONE_8_0 for OS X 10.10 is __MAC_10_10.

Why?

If you are interested in why these messages exist, you can check out this SO answer or these Apple docs.

Community
  • 1
  • 1
Clay Bridges
  • 11,602
  • 10
  • 68
  • 118