<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 27, 2017, at 10:39 AM, tuuranton--- via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
<div class="">
Yes, but why?<div class=""><br class=""><div class="">What's the rationale for this?</div><div class=""><br class=""></div><div class="">What would be so bad about allowing overriding a non-failable initializer with a failable initializer?</div></div></div></div></blockquote><div><br class=""></div>If the non-failable initializer witnesses a non-failable protocol requirement, and the subclass overrides it, what should be the runtime behavior if the subclass initializer returns nil? The caller won’t expect it, since the caller is calling a non-failable initializer.</div><div><br class=""></div><div>For similar reasons, you cannot override a method that returns a non-optional value with a method returning an optional value.</div><div><br class=""></div><div>Slava</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class=""><div class=""><br class="">27. Jan 2017 18:59 by <a href="mailto:saagar@saagarjha.com" target="_blank" rel="noopener noreferrer" class="">saagar@saagarjha.com</a>:<br class=""><br class=""><blockquote class="tutanota_quote" style="border-left: 1px solid #93A3B8; padding-left: 10px; margin-left: 5px;">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.<div class=""><br class=""><div class="">
<div style="letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class="">Saagar Jha</div>
</div>
<br class=""><div class=""><blockquote class="thunderbird_quote" style="border-left: 1px solid #93a3b8 ; padding-left: 10px ; margin-left: 5px"><div class="">On Jan 27, 2017, at 8:45 AM, tuuranton--- via swift-users <<a href="mailto:swift-users@swift.org" target="_blank" rel="noopener noreferrer" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<div class="">
<div class="">See the comments. Why is one allowed but the other one isn't and what's the rationale for this?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">class Vehicle {</div><div class=""> let name: String</div><div class=""> init(name: String) {</div><div class=""> self.name = name</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">class Car: Vehicle {</div><div class=""> //Why is this not allowed?</div><div class=""> override init?(name: String) {</div><div class=""> super.init(name: name)</div><div class=""> }</div><div class=""> </div><div class=""> //But this is allowed?</div><div class=""> init?(name: String, ignore: String) {</div><div class=""> super.init(name: name)</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div> </div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" rel="noopener noreferrer" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" rel="noopener noreferrer" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></blockquote></div></div> </div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>