<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=""><div class="">I am trying to write an extension to a UIKit class, but am running into a can’t-win situation:</div><div class=""><br class=""></div><div class="">The code I ‘want’ to write looks like:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 252, 234); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(195, 89, 0); background-color: rgb(255, 252, 234);" class=""><span style="color: #36568a" class="">public</span><span style="color: #000000" class=""> </span><span style="color: #36568a" class="">extension</span><span style="color: #000000" class=""> </span>UISplitViewController<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 252, 234);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #36568a" class="">override</span> <span style="color: #36568a" class="">public</span> <span style="color: #36568a" class="">func</span> <span style="text-decoration: underline" class="">v</span>iewDidLoad() {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168); background-color: rgb(255, 252, 234);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="color: #36568a" class="">super</span><span style="color: #000000" class="">.</span>viewDidLoad<span style="color: #000000" class="">()</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168); background-color: rgb(255, 252, 234);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="color: #36568a" class="">if</span><span style="color: #000000" class=""> </span><span style="color: #c35900" class="">UIDevice</span><span style="color: #000000" class="">.</span>current<span style="color: #000000" class="">.</span>userInterfaceIdiom<span style="color: #000000" class=""> == .</span>pad<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168); background-color: rgb(255, 252, 234);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span></span>preferredDisplayMode<span style="color: #000000" class=""> = .</span>automatic</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 252, 234);" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>} <span style="color: #36568a" class="">else</span> {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168); background-color: rgb(255, 252, 234);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span></span>preferredDisplayMode<span style="color: #000000" class=""> = .</span>primaryOverlay</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 252, 234);" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 252, 234);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; background-color: rgb(255, 252, 234);" class="">}</div></div><div class=""><br class=""></div><div class="">This generates the error message&nbsp;</div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class="">/Users/rlaurb/Projects/Cooks-Memory/Cooks-Memory/AppDelegate.swift:131:23: Overriding instance method must be as accessible as the declaration it overrides</div></div><div class=""><div class="">/Users/rlaurb/Projects/Cooks-Memory/Cooks-Memory/AppDelegate.swift:131:23: Overridden declaration is here (UIKit.UIViewController)</div></div><div class=""><br class=""></div></blockquote>But I can’t change the access control of the function to ‘open’, because I get the warning that the function can’t be “more” accessible than the extension.<div class=""><br class=""></div><div class="">And I can’t change the extension’s access to ‘open’ because apparently extensions can’t be open.</div><div class=""><br class=""></div><div class="">Now I don’t want to get into a debate about whether this code works — it’s just an experiment — but is it even possible to express this idea?? I.e., is it possible to express this idea without subclassing?<br class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="text-align: start; text-indent: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="text-align: start; text-indent: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="text-align: start; text-indent: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="text-align: start; text-indent: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="text-align: start; text-indent: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="text-align: start; text-indent: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="text-align: start; text-indent: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="orphans: 2; text-align: -webkit-auto; text-indent: 0px; widows: 2;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="orphans: 2; text-indent: 0px; widows: 2;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="orphans: 2; text-indent: 0px; widows: 2;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="orphans: 2; text-indent: 0px; widows: 2;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; orphans: 2; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; orphans: 2; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; orphans: 2; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; orphans: 2; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; orphans: 2; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; orphans: 2; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div style="color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">Cheers,</div><div style="color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">Rick Aurbach</div><div style="color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class=""><br class=""></div></div></div></span></div></span></div></span></div></span></div></span></div></span></div></span></div></span></div></span></div></span></div></span></div></div></div></div></div></div></div></div></div></div></body></html>