Xcode-beta (7A120f): Marking a superclass's designated initializer as NS_UNAVAILABLE now generates a -Wobjc-designated-initializers warning
| Originator: | rmaloney27 | ||
| Number: | rdar://21782697 | Date Originated: | 11-Jul-2015 12:55 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-beta (7A120f) |
| Classification: | Other Bug | Reproducible: | Always |
Summary: If a superclass’s designated initializer is marked as NS_UNAVAILABLE in your header file, it will generate an error if a user of that class attempts to call it. This is great when creating objects that require additional data in order to be properly initialized. In Xcode 7.0 beta (7A120f), all of my classes that have disabled their superclass’s designated initializers via NS_UNAVAILABLE are now generating a -Wobjc-designated-initializers warning, saying that an override for the superclass’s designated initializer is not found (even though my designated initializers are calling into their superclass’s designated initializers via [super init]). This is the incorrect behavior because: 1. The subclass’s designated initializer is calling into it’s superclass’s designated initializer. 2. The superclass’s designated initializer is marked as NS_UNAVAILABLE in the subclass’s header file. 3. The subclass requires that certain parameters be used on initialization for the object to be properly initialized. Steps to Reproduce: 1. Create a subclass of NSObject 2. In the header file, mark -init as NS_UNAVAILABLE 3. In the header file, define a new designated initializer such as -initWithRequiredInt:(int)required NS_DESIGNATED_INITIALIZER 4. In the implementation file, implement -initWithRequiredInt: such that it calls [super init] (NSObject’s designated initializer). 5. Build Expected Results: No warning’s should be generated Actual Results: A -Wobjc-designated-initializers warning is generated
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!