Swift: Cannot add an initializer to an NSProxy subclass
| Originator: | lithium3141 | ||
| Number: | rdar://18548454 | Date Originated: | 04-Oct-2014 03:58 PM |
| Status: | Open | Resolved: | |
| Product: | OS X SDK | Product Version: | Xcode 6.0.1 (6A317) / OS X 10.10 (14A361c) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
In Swift, it is a requirement that initializers call a superclass initializer before returning. However, NSProxy is documented as an abstract class, and provides no initializer to call. As such, it is impossible to subclass NSProxy and add an initializer.
Swift should allow adding an initializer on an NSProxy subclass, either by adding general support for abstract superclasses or by special-casing this one class.
Steps to Reproduce:
1. Create a new Swift playground
2. Add the following code:
import Foundation
class Proxy: NSProxy {
init() { }
}
3. Compile
Expected Results:
The class compiles successfully, since NSProxy provides no superclass initializer to call from Proxy.init()
Actual Results:
The compiler issues an error: "Super.init isn't called before returning from initializer"
Version:
Xcode 6.0.1 (6A317) / OS X 10.10 (14A361c)
Notes:
Adding the requested superclass call to Proxy.init() in the above example produces a different error: "'NSProxy' does not have a member named 'init'"
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!