<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I found two workarounds.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">1.</div><div class="gmail_default" style="font-family:georgia,serif"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures">protocol</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> Foo: </span><span style="font-variant-ligatures:no-common-ligatures">class</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Base:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">@objc</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">&quot;bar&quot;</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Baz: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Base</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures">override</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">init</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">super</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> tapRecognizer = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">UITapGestureRecognizer</span><span style="font-variant-ligatures:no-common-ligatures">(target: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">#selector</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">bar</span><span style="font-variant-ligatures:no-common-ligatures">))</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">2.</div><div class="gmail_default" style="font-family:georgia,serif"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures">protocol</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> Foo: </span><span style="font-variant-ligatures:no-common-ligatures">class</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures">extension</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">&quot;bar&quot;</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Baz: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> tapRecognizer = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">UITapGestureRecognizer</span><span style="font-variant-ligatures:no-common-ligatures">(target: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">#selector</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">delegate</span><span style="font-variant-ligatures:no-common-ligatures">))</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">@objc</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> delegate() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">bar</span><span style="font-variant-ligatures:no-common-ligatures">()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhao Xin</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jun 3, 2017 at 10:35 AM, Nate Birkholz via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">protocol Foo: class {<div>    func bar()<br><div><div>}</div><div><br></div><div>extension Foo {</div><div>    func bar() {</div><div>         print(&quot;bar&quot;)</div><div>    }</div><div>}</div><div><br></div><div>class Baz: Foo {</div></div></div><div>    init() {</div><div>        let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(bar))</div><div>    }</div><div><div>}</div><div><br></div><div>the #selector tells me: &quot;Argument of &#39;#selector&#39; refers to instance method &#39;bar()&#39; that is not exposed to Objective-C&quot; and asks me to add @objc to the method definition. </div><div><br></div><div>Adding @objc to the method tells me: &quot;@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes&quot;</div><div><br></div><div>Adding @objc to the protocol doesn&#39;t fix it, just introduces new issues.</div><div><br></div><div>&quot;dynamic&quot; cannot be applied to a protocol, so cannot be used alternatively. </div><div><br></div><div>Is there a way to get around this? If a method is called by a gesture recognizer, is there no way to have a default protocol implementation? I&#39;d like to use default implementations if possible to make my code more DRY.</div><div><br></div><div>Is there a roadmap/plan for swift-native selector dispatch?</div><div><br></div><div>Thanks. I look forward to the inevitable reply revealing the dumb thing I missed. :)</div><span class="HOEnZb"><font color="#888888"><div><div><br></div>-- <br><div class="m_8246596659823059447gmail_signature">Nate Birkholz</div>
</div></font></span></div></div>
<br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>