Define a macro like this
#define FOO_DESIGNATED_INITIALIZER NS_DESIGNATED_INITIALIZER; \ /** Unavailable. Use the designated initializer instead */ \ + (instancetype)new NS_UNAVAILABLE; \ /** Unavailable. Use the designated initializer instead */ \ - (instancetype)init NS_UNAVAILABLE; \
So you can do this
- (instancetype)initWithBar:(Bar *)bar FOO_DESIGNATED_INITIALIZER;
Aug 08, 2017 @ 18:32:18
Huh? Having a designated initializer doesn’t mean that you cannot or should not have +new or -init. All the designated initializer is is the override point that calls super and should be called by all other initializers.
It is perfectly fine, useful and common to have -init and +new implemented, calling the designated initializer with default values.
Aug 12, 2017 @ 22:14:29
Hi Marcel. It depends on your intent. Use this macro if you don’t want others to use +new or -init (because your object would be in an undefined state). Else don’t as you suggest. Cheers.