On Jun 9, 2015, at 15:23 , Sean McBride <email@hidden> wrote:
I also tried:
- (instancetype)init { assert(0); }
Thinking maybe it would clue in on an old school assert, but no.
I was half-right before, in that using ’NS_DESIGNATED_INITIALIZER’ enables different rules for initializers in the compiler. Once you use that on an initializer that has parameters, you must override parameterless ‘init’ too, and the override has to be a designated initializer.
However, the syntax I suggested was wrong. You can only use ’NS_DESIGNATED_INITIALIZER’ in an @interface block, so you’d actually do it like this (in the .m file):
@interface MyClass () - (instancetype) init NS_DESIGNATED_INITIALIZER; @end
@implementation MyClass - (instancetype) init { assert (0); }
Note that if you have other private initializer methods in the @implementation block only, you’ll have to pre-declare them in the class extensions so that you can mark the ’NS_DESIGNATED_INITIALIZER’ too.
I tried this in an actual source file, and the warnings did go away.
|