Designated initializer overriding issues in Objective-C

Originator:an00na
Number:rdar://21331649 Date Originated:10-Jun-2015 06:54 PM
Status:Behaves as Intended Resolved:
Product:Developer Tools Product Version:Xcode 7.0 beta 1
Classification:Serious Bug Reproducible:Always
 
Summary:
Adding a new designated initializer in subclass causes self-contradicting warnings:
1. “Method override for the designated initializer of the superclass ‘-init…:’ not found”.
2. After overriding ‘-init…:’ by delegating to super, “Convenience initializer should not invoke an initializer on 'super’”, “Convenience initializer missing a 'self' call to another initializer”.

The issues are:
1. Why are designated initializers no longer designated after being overridden in subclass?
2. Why must subclass override superclass’s designated initializers?

If we want a strictly sound initializer system like Swift, new designated initializers in subclass should render superclass’s designated initializers unavailable to call on subclass. It shouldn’t force subclass to override those designated initializers if no one use them on subclass. If subclass wants to override them, or have to override them because users need to call them on subclass, overriding them shouldn’t change them to convenience initializers automatically.

One cause of the issues I can think of is that Objc and Swift are opposite with respect to the default role of initializers: In Swift initializers are designated by default, unless annotated with convenience keyword; In Objc, initializers are convenience by default, unless annotated with NS_DESIGNATED_INITIALIZER.

If this means that overriding designated initializers without annotation makes them convenience initializers by default, then we need a way to conveniently annotate them designated. Currently, NS_DESIGNATED_INITIALIZER can only be used on declaration but not on definition, so we have to redeclare them with NS_DESIGNATED_INITIALIZER in subclass to keep them designated, which is very inconvenient.


Steps to Reproduce:
Just try solving all the warnings and you’ll see the issues.


Sample code:
http://cl.ly/0q1L2z291H0g


Apple response:
This issue behaves as intended based on the following:

Please see this document:
https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/Initialization/Initialization.html#//apple_ref/doc/uid/TP40010810-CH6-SW3

This explains the designated initializer patterns.

We are now closing this bug report.

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.

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!