Turn off designated initializer checking in Xcode 6

Clay Bridges picture Clay Bridges · Aug 21, 2014 · Viewed 8.6k times · Source

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?

Answer

bandejapaisa picture bandejapaisa · Nov 26, 2014

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.