<div dir="auto"><br></div><div><br><div class="gmail_quote"><div dir="auto">Adrian Zubarev via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> schrieb am Mi. 20. Sep. 2017 um 22:13:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div id="m_2141320775040486934bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">I don’t get your problem here. If you don’t want to debate the correctness of your code, why are you asking for help or even showing error messages for a code snippet that cannot work?</div><div id="m_2141320775040486934bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div id="m_2141320775040486934bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">1. Drop the access modifier from the extension itself, because this is only for convenience, which may or may not rule over the members of the extension members. If you’re already explicitly setting the access modifier on the extension members then the convenience access modifier makes no sense.</div><div id="m_2141320775040486934bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">2. The code cannot work, because you cannot override `viewDidLoad` on a class that you don’t own, on a subclass of `UISplitViewController` that would be possible.</div></div></blockquote><div dir="auto"><br></div><div dir="auto">I think the point is that this is possible in ObjcC. So the question is really whether you can override methods in Swift from classes that are not your own.</div><div dir="auto"><br></div><div dir="auto">The answer, as far as I’ve seen, is no. Whenever I’ve needed this feature I’ve used ObjC.</div><div dir="auto"><br></div><div dir="auto">- Geordie</div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div id="m_2141320775040486934bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"></div> <div><br></div>```<div><div>class MySplitViewController : UISplitViewController {}</div><div><br></div><div>extension MySplitViewController {</div><div><span class="m_2141320775040486934Apple-tab-span" style="white-space:pre-wrap">        </span>override open func viewDidLoad() {</div><div><span class="m_2141320775040486934Apple-tab-span" style="white-space:pre-wrap">                </span>super.viewDidLoad()</div><div><span class="m_2141320775040486934Apple-tab-span" style="white-space:pre-wrap">                </span>/* ... */</div><div><span class="m_2141320775040486934Apple-tab-span" style="white-space:pre-wrap">        </span>}</div><div>}</div></div><div>```</div></div><div style="word-wrap:break-word"><div><br> <div id="m_2141320775040486934bloop_sign_1505937863196648192" class="m_2141320775040486934bloop_sign"></div> <br><p class="m_2141320775040486934airmail_on">Am 20. September 2017 um 21:41:31, Rick Aurbach via swift-users (<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>) schrieb:</p> <blockquote type="cite" class="m_2141320775040486934clean_bq"><span><div style="word-wrap:break-word"><div></div><div>
<div>I am trying to write an extension to a UIKit class,
but am running into a can’t-win situation:</div>
<div><br></div>
<div>The code I ‘want’ to write looks like:</div>
<div><br></div>
<div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;background-color:rgb(255,252,234);min-height:14px"><br></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)"><span style="color:#36568a">public</span>
<span style="color:#36568a">extension</span>
UISplitViewController <span style="color:#000000">{</span></div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;background-color:rgb(255,252,234)"><span style="color:#36568a">override</span>
<span style="color:#36568a">public</span> <span style="color:#36568a">func</span> <span style="text-decoration:underline">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)"><span style="color:#36568a">super</span><span style="color:#000000">.</span>viewDidLoad<span style="color:#000000">()</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)"><span style="color:#36568a">if</span>
<span style="color:#c35900">UIDevice</span><span style="color:#000000">.</span>current<span style="color:#000000">.</span>userInterfaceIdiom <span style="color:#000000">== .</span>pad <span style="color:#000000">{</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)">preferredDisplayMode <span style="color:#000000">= .</span>automatic</div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;background-color:rgb(255,252,234)">} <span style="color:#36568a">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)">preferredDisplayMode <span style="color:#000000">= .</span>primaryOverlay</div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;background-color:rgb(255,252,234)">}</div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;background-color:rgb(255,252,234)">}</div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;background-color:rgb(255,252,234)">}</div>
</div>
<div><br></div>
<div>This generates the error message </div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>
<div>
/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>
<div>
/Users/rlaurb/Projects/Cooks-Memory/Cooks-Memory/AppDelegate.swift:131:23:
Overridden declaration is here (UIKit.UIViewController)</div>
</div>
<div><br></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><br></div>
<div>And I can’t change the extension’s access to ‘open’
because apparently extensions can’t be open.</div>
<div><br></div>
<div>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>
<br>
<div>
<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;word-wrap:break-word">
<div style="text-align:start;text-indent:0px;word-wrap:break-word">
<div style="text-align:start;text-indent:0px;word-wrap:break-word">
<div style="text-align:start;text-indent:0px;word-wrap:break-word">
<div style="text-align:start;text-indent:0px;word-wrap:break-word">
<div style="text-align:start;text-indent:0px;word-wrap:break-word">
<div style="text-align:start;text-indent:0px;word-wrap:break-word">
<div style="text-align:start;text-indent:0px;word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-transform:none;white-space:normal;word-spacing:0px">
<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-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_2141320775040486934Apple-style-span" style="border-collapse:separate;border-spacing:0px">Cheers,</span></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-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_2141320775040486934Apple-style-span" style="border-collapse:separate;border-spacing:0px"><br></span></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-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_2141320775040486934Apple-style-span" style="border-collapse:separate;border-spacing:0px">Rick
Aurbach</span></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-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_2141320775040486934Apple-style-span" style="border-collapse:separate;border-spacing:0px"><br></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br></div></div></span></blockquote></div></div>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div></div>