Last active
January 6, 2024 07:24
-
-
Save steipete/9482253 to your computer and use it in GitHub Desktop.
Declare on your main init that all other init methods should call. It's a nice additional semantic warning. Works with Xcode 5.1 and above. Not tested with earlier variants, but should just be ignored. A reference to this macro shortly appeared in https://developer.apple.com/library/ios/releasenotes/ObjectiveC/ModernizationObjC/AdoptingModernObj…
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
#ifndef NS_DESIGNATED_INITIALIZER | |
#if __has_attribute(objc_designated_initializer) | |
#define NS_DESIGNATED_INITIALIZER __attribute((objc_designated_initializer)) | |
#else | |
#define NS_DESIGNATED_INITIALIZER | |
#endif | |
#endif |
@lukabernardi unavailable
produces a compiler error that prevents accidental misbehavior. Intentional wrongdoers will be able to skip any other check you add.
@nzhuk This is so stupid :( And when you use the unavailable
attribute, you can't redefine that method in the subclass in order to make it available again >__< .. Need.. Swift.. Now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This attribute is problematic in UIViewController subclasses. If you introduce your own init method and mark it as __attribute((objc_designated_initializer)), you'll get compiler warnings even if you do call the designated initializer of the superclass from it (i.e. [super initWithNibName:bundle:] ), since -[UIViewController initWithNibName:bundle:] is documented as designated initializer but not marked as such with this attribute.