[swift-users] Initializers

Saagar Jha saagar at saagarjha.com
Fri Jan 27 11:59:57 CST 2017


You can’t override a designated initializer with one that is failable. The second one is defining a new initializer that is failable, instead of overriding the one from its superclass.

Saagar Jha

> On Jan 27, 2017, at 8:45 AM, tuuranton--- via swift-users <swift-users at swift.org> wrote:
> 
> See the comments. Why is one allowed but the other one isn't and what's the rationale for this?
> 
> 
> class Vehicle {
>     let name: String
>     init(name: String) {
>         self.name = name
>     }
> }
> 
> 
> class Car: Vehicle {
>     //Why is this not allowed?
>     override init?(name: String) {
>         super.init(name: name)
>     }
>     
>     //But this is allowed?
>     init?(name: String, ignore: String) {
>         super.init(name: name)
>     }
> }
> 
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170127/feabd9cf/attachment.html>


More information about the swift-users mailing list