Last active
June 27, 2023 10:25
-
-
Save JaviSoto/5906004 to your computer and use it in GitHub Desktop.
Mark designated initializer at compile time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
unfortunately this does not recognize
[SampleClass new]
, only[[SampleClass alloc] init]
... is there a way to avoidnew
as well?