Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
Last active June 27, 2023 10:25
Show Gist options
  • Save JaviSoto/5906004 to your computer and use it in GitHub Desktop.
Save JaviSoto/5906004 to your computer and use it in GitHub Desktop.
Mark designated initializer at compile time
#define MSDesignatedInitializer(__SEL__) __attribute__((unavailable("Invoke the designated initializer `" # __SEL__ "` instead.")))
// Sample usage:
- (instancetype)initWithObject:(id)object;
- (instancetype)init MSDesignatedInitializer(initWithObject:); // <- This even gets auto-complete.
// Now calling init on this class would throw a warning.
@haemi
Copy link

haemi commented Jul 16, 2013

unfortunately this does not recognize [SampleClass new], only [[SampleClass alloc] init]... is there a way to avoid newas well?

@ZevEisenberg
Copy link

@haemi You would probably have to mark + (instancetype)new in the same manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment