<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 May 16, 2016, at 7:09 AM, tuuranton--- via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">
  
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
  
  <div class="">
<div class="">Why does the following code compile?</div><div class="">Why does Bar's init(x: Int) automatically call Foo's init()?</div><div class="">Why don't I have to manually call super.init() myself?</div></div></div></blockquote><div><br class=""></div><div>This is intentional behavior. &nbsp;It kicks in when your super class has a single designated initializer with a zero-argument init. &nbsp;This is why you don’t have to call super.init() when deriving from NSObject.</div><div><br class=""></div><div>-Chris</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">What passage of</div><div class=""><a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-ID203" target="_blank" class="">https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-ID203</a></div><div class="">tells me that this should be the case?</div><div class=""><br class=""></div><div class="">--------------------</div><div class="">class Foo {</div><div class="">&nbsp; &nbsp; init() {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; print("foo init")</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class="">class Bar: Foo {</div><div class="">&nbsp; &nbsp; init(x: Int) {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; print("bar init")</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class="">let b = Bar(x: 0)</div><div class="">//prints:</div><div class="">// &nbsp; &nbsp;bar init</div><div class="">// &nbsp; &nbsp;foo init</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>