Xcode 6.1 (6A1030): Cannot conform to a protocol including an initializer in an extension to a non-final class.

Originator:janoschhildebrand
Number:rdar://18373343 Date Originated:18-Sep-2014
Status:Duplicate of 18388281 (Closed) Resolved:
Product:Developer Tools Product Version:Xcode 6.1 (6A1030)
Classification:Feature Request Reproducible:NA
 
Summary:
Currently there is no way to conform to a protocol including an initializer in an extension to a non-final class.

Take the following protocol:

protocol Protocol {
    init(aNumber: Int)
}

Now we want an existing, non-final class defined somewhere else to conform to this protocol:

extension NSData: Protocol {
   init(aNumber: Int) {
        // ...
    }
}

Unfortunately this is currently impossible. Only convenience initializers are allowed in extensions and a convenience initializer can't be used in this case as the class is non-final and thus the protocol conformance must be inherited by all subclasses.


It would be great if this would be possible in some way. Perhaps by being able to add non-convenience initializers in extensions or some other way.

Steps to Reproduce:


Expected Results:


Actual Results:


Version:
Xcode 6.1 (6A1030)
Swift version 1.1 (swift-600.0.54.4)
OSX 10.10 (14A361c)

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!