<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hello community,&nbsp;</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>I just encountered a pretty weird behavior when I subclass &nbsp;`UINavigationController` without overriding any initializers.</div><div class=""><br class=""></div>Simple Code:<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">import UIKit</font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class=""><br class=""></font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">class MyViewController: UINavigationController {</font></div></div><div class=""><p style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 15px;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">&nbsp;&nbsp;</font></p></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">&nbsp; let value: Int = {</font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">&nbsp; &nbsp; print("member init")</font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">&nbsp; &nbsp; return 3</font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">&nbsp; }()</font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">}</font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class=""><br class=""></font></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" style="background-color: rgb(255, 255, 255); font-size: 12px;" color="#0433ff" class="">let _ = MyViewController(rootViewController: UIViewController())</font></div></div></blockquote><div class=""><br class=""></div><div class="">output is:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);" class=""><b class="">member init</b></span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);" class=""><b class="">member init</b></span></div></div></blockquote><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);" class=""><b class=""><br class=""></b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="background-color: rgb(255, 255, 255);" class="">In fact any member variables declared in this subclass is initialized twice but deinitialized only once.</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="background-color: rgb(255, 255, 255);" class="">This phenomenon only appears when using `init(rootViewController:)`.&nbsp;</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="background-color: rgb(255, 255, 255);" class="">CMIW, It looks like Swift somehow treat this initializer as a designated initializer, rather than a convenience one.&nbsp;</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="background-color: rgb(255, 255, 255);" class="">Any Ideas?</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);" class=""><b class=""><br class=""></b></span></div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);" class=""><b class=""><br class=""></b></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""><br class=""></b></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""><br class=""></b></span></div><div class=""><br class=""></div></body></html>