<div dir="ltr">Technically it does work(!), but I am hesitant to use it in what amounts to sample code for my current job search, haha.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 4, 2017 at 4:55 AM, Zhao Xin <span dir="ltr">&lt;<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</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"><div class="gmail_default" style="font-family:georgia,serif">Will this work?</div><div class="gmail_default" style="font-family:georgia,serif"><br></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(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"> TapGestureRecognizer: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">UITapGestureRecognizer</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)">var</span><span style="font-variant-ligatures:no-common-ligatures"> onTap: (() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Void</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">(onTap: (() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Void</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)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">onTap</span><span style="font-variant-ligatures:no-common-ligatures"> = onTap</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">(target: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">nil</span><span style="font-variant-ligatures:no-common-ligatures">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">nil</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)"><b><i><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">removeTarget</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">nil</span><span style="font-variant-ligatures:no-common-ligatures">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">nil</span><span style="font-variant-ligatures:no-common-ligatures">)</span></i></b></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)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">addTarget</span><span style="font-variant-ligatures:no-common-ligatures">(</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)">internalTapHandler</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(62,30,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</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)">private</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"> internalTapHandler() {</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(79,129,135)">onTap</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">Zhao Xin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 4, 2017 at 5:24 PM, Nate Birkholz <span dir="ltr">&lt;<a href="mailto:nbirkholz@gmail.com" target="_blank">nbirkholz@gmail.com</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">Also, note that I tried the following:<div><br><div><div>class BlockTapGestureRecognizer: UIGestureRecognizer {</div><span><div>    var onTap: (() -&gt; Void)?</div><div>    init(onTap: (() -&gt; Void)?) {</div><div>        self.onTap = onTap</div></span><div>        super.init(target: nil, action: nil)</div><div>        self.addTarget(self, action: #selector(internalTapHandler))</div><div>        print(self)</div><span><div>    }</div><div><br></div><div>    @objc private func internalTapHandler() {</div><div>        onTap?()</div><div>    }</div><div>}</div></span></div><div><br></div><div>And the object prints looking okay:</div><div><br><div><div>&lt;Artmospherez.BlockTapGestureR<wbr>ecognizer: 0x1701998b0; baseClass = UIGestureRecognizer; state = Possible; view = &lt;UIView 0x100c60870&gt;; target= &lt;(action=internalTapHandler, target=&lt;Artmospherez.BlockTapG<wbr>estureRecognizer 0x1701998b0&gt;)&gt;&gt;<br></div><div><br></div><div>But it doesn&#39;t in practice work. The documentation for the (target: action:) initializer states:</div></div><div><div><br></div><div>target: An object that is the recipient of action messages sent by the receiver when it recognizes a gesture. nil is not a valid value.</div><div>action: A selector that identifies the method implemented by the target to handle the gesture recognized by the receiver. The action selector must conform to the signature described in the class overview. NULL is not a valid value.</div></div><div><br></div><div>So something is going on inside there when the nil values are passed to the recognizer. As the documentation states, nil is not a valid value and it must cause troubles.</div><div><br></div><div>Or I did something wrong?</div><div><br></div><div><br></div></div></div></div><div class="gmail_extra"><div><div class="m_545045860956791860h5"><br><div class="gmail_quote">On Sun, Jun 4, 2017 at 1:55 AM, Nate Birkholz <span dir="ltr">&lt;<a href="mailto:nbirkholz@gmail.com" target="_blank">nbirkholz@gmail.com</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">Ah, I didn&#39;t read the rest of the thread. As Zhao Xin notes, you cannot call super.init(target: self, action: #selector()), and you cannot call super.init() in a subclass init or convenience init, it *has* to be the designated init method init(target:action:). That&#39;s too bad, closure-based gesture recognizers would be snazzy and swifty and I&#39;d love to see them as part of UIKit. <div><br></div><div>I could write my own custom implementations of subclassed UIKit.UIGestureRecognizerSubcl<wbr>ass(es), but as the screens in question have tap, swipe up, swipe down, and swipe right gesture recognizers, I feel its overkill to write all that to avoid repeating ~10 lines of code.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 4, 2017 at 1:21 AM, Nate Birkholz <span dir="ltr">&lt;<a href="mailto:nbirkholz@gmail.com" target="_blank">nbirkholz@gmail.com</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="auto"><div>I briefly considered something like this but didn&#39;t explore it. Elegant.<br><br>Sent from my iPhone, please excuse brevity and errors</div><div><br>On Jun 3, 2017, at 9:38 PM, Geordie Jay &lt;<a href="mailto:geojay@gmail.com" target="_blank">geojay@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>I am dealing with a variant of this on Android right now. I have just subclassed e.g. UITapGestureRecognizer to perform the 2nd variant above and externally accept a closure as its argument. I&#39;m writing this on my phone so forgive any syntax errors or accidental omissions:<br><br>class TapGestureRecognizer: UITapGestureRecognizer {<br>  var onTap: (() -&gt; Void)?<br>  init(onTap: (() -&gt; Void)?) {<br>    self.onTap = onTap<br>    super.init(target: self, action: #selector(internalTapHandler))<br>  }<br><br>  @objc private func internalTapHandler() {<br>    onTap?()<br>  }<br>}<br><br>class Baz: Foo {<br>  init() {<br>    let tapRecognizer = TapGestureRecognizer(onTap: self.bar)<br>  }<br>}<br><br><br>Cheers,<br>Geordie<br><div class="gmail_quote"><div dir="ltr">On Sat 3. Jun 2017 at 16:53, Nate Birkholz via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks, the second had occurred to me, but felt a little too much like in practice it would make the code harder to understand.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 2, 2017 at 9:58 PM, Zhao Xin <span dir="ltr">&lt;<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</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"><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="m_545045860956791860m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888"><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288HOEnZb"><font color="#888888"><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288m_7008235823108254220HOEnZb"><font color="#888888"><div><div><br></div>-- <br><div class="m_545045860956791860m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288m_7008235823108254220m_8246596659823059447gmail_signature">Nate Birkholz</div>
</div></font></span></font></span></font></span></div></div><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888"><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288HOEnZb"><font color="#888888">
<br>______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/swift-users</a><br>
<br></font></span></font></span></blockquote></div><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888"><br></font></span></div><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888"><br><br clear="all"><span class="m_545045860956791860m_6716881662020614998HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_545045860956791860m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288gmail_signature" data-smartmail="gmail_signature">Nate Birkholz</div>
</font></span></font></span></div><span class="m_545045860956791860m_6716881662020614998HOEnZb"><font color="#888888"><span class="m_545045860956791860m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888">
______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/swift-users</a><br>
</font></span></font></span></blockquote></div><span class="m_545045860956791860m_6716881662020614998HOEnZb"><font color="#888888">
</font></span></div></blockquote></div></blockquote></div><span class="m_545045860956791860m_6716881662020614998HOEnZb"><font color="#888888"><br><br clear="all"><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_545045860956791860m_6716881662020614998m_-2127668203321951367gmail_signature" data-smartmail="gmail_signature">Nate Birkholz</div>
</font></span></font></span></div><span class="HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div></font></span></div></div><span class="HOEnZb"><font color="#888888"><span class="m_545045860956791860HOEnZb"><font color="#888888">-- <br><div class="m_545045860956791860m_6716881662020614998gmail_signature" data-smartmail="gmail_signature">Nate Birkholz</div>
</font></span></font></span></div>
</blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Nate Birkholz</div>
</div>