<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="">In fact, this would be even better (avoids unnecessary implicitly unwrapped optionals):<div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ClosureGestureRecognizer<GestureRecognizer: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIGestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">fileprivate</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> recognizer: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">GestureRecognizer</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> onAction: ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">GestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(onAction: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@escaping</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">GestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) {</span></div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">recognizer</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures" class="">GestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">()</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">onAction</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = onAction</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">recognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">addTarget</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">, action: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">#selector</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">actionHandler</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@objc</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> actionHandler() {</span></div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">onAction</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">recognizer</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> addGestureRecognizer<T>(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> gestureRecognizer: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ClosureGestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">>) {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">addGestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">(gestureRecognizer.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">recognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">Depending on your use-case, it’d be no problem to make <i style="font-family: Helvetica; font-size: 12px;" class="">onAction</i> a non-private (externally settable) optional closure—in case you want to avoid having to set it on init of ClosureGestureRecognizer.</span></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div></div></div><div class="">Cheers,</div><div class="">Geordie</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 04.06.2017 um 23:09 schrieb Geordie J <<a href="mailto:geojay@gmail.com" class="">geojay@gmail.com</a>>:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class="">To get around the issue of using self on init, but also that of multiple recogniser types, try this:</div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class=""><br class=""></span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ClosureGestureRecognizer<RecognizerType: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIGestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">> {</span></div><div style="color: rgb(0, 132, 0); font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// These are initially nil and set on init to their desired values.</span></div><div style="color: rgb(0, 132, 0); font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> // This gets around the issue of using self in init.</span></div><div style="color: rgb(0, 132, 0); font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> // `private` means they can't ever actually be nil:</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> recognizer: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">RecognizerType</span><span style="font-variant-ligatures: no-common-ligatures" class="">!</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> onAction: ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">RecognizerType</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">)!</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(callback: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@escaping</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">RecognizerType</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) {</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">recognizer</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">RecognizerType</span><span style="font-variant-ligatures: no-common-ligatures" class="">(target: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">, action: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">#selector</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">actionHandler</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">onAction</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = callback</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@objc</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> actionHandler() {</span></div><div style="color: rgb(79, 129, 135); font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">onAction</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">recognizer</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> recognizer = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ClosureGestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIPanGestureRecognizer</span><span style="font-variant-ligatures: no-common-ligatures" class="">>(callback: { panGestureRecognizer </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Panned, translation:"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, panGestureRecognizer.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">translation</span><span style="font-variant-ligatures: no-common-ligatures" class="">(in: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="font-family: Menlo; margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">})</span></div><div style="color: rgb(255, 255, 255); font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div></div><div class="">Regards,</div><div class="">Geordie</div><br class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 04.06.2017 um 21:55 schrieb Zhao Xin <<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>>:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">Will this work?</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> TapGestureRecognizer: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">UITapGestureRecognizer</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> onTap: (() -> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Void</span><span style="font-variant-ligatures:no-common-ligatures" class="">)?</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(onTap: (() -> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Void</span><span style="font-variant-ligatures:no-common-ligatures" class="">)?) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">onTap</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = onTap</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">super</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(target: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">nil</span><span style="font-variant-ligatures:no-common-ligatures" class="">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">nil</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><b class=""><i class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">removeTarget</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">nil</span><span style="font-variant-ligatures:no-common-ligatures" class="">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">nil</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></i></b></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">addTarget</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">#selector</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">internalTapHandler</span><span style="font-variant-ligatures:no-common-ligatures" class="">))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">@objc</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">private</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> internalTapHandler() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">onTap</span><span style="font-variant-ligatures:no-common-ligatures" class="">?()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">Zhao Xin</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Jun 4, 2017 at 5:24 PM, Nate Birkholz <span dir="ltr" class=""><<a href="mailto:nbirkholz@gmail.com" target="_blank" class="">nbirkholz@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Also, note that I tried the following:<div class=""><br class=""><div class=""><div class="">class BlockTapGestureRecognizer: UIGestureRecognizer {</div><span class=""><div class=""> var onTap: (() -> Void)?</div><div class=""> init(onTap: (() -> Void)?) {</div><div class=""> self.onTap = onTap</div></span><div class=""> super.init(target: nil, action: nil)</div><div class=""> self.addTarget(self, action: #selector(internalTapHandler))</div><div class=""> print(self)</div><span class=""><div class=""> }</div><div class=""><br class=""></div><div class=""> @objc private func internalTapHandler() {</div><div class=""> onTap?()</div><div class=""> }</div><div class="">}</div></span></div><div class=""><br class=""></div><div class="">And the object prints looking okay:</div><div class=""><br class=""><div class=""><div class=""><Artmospherez.<wbr class="">BlockTapGestureRecognizer: 0x1701998b0; baseClass = UIGestureRecognizer; state = Possible; view = <UIView 0x100c60870>; target= <(action=internalTapHandler, target=<Artmospherez.<wbr class="">BlockTapGestureRecognizer 0x1701998b0>)>><br class=""></div><div class=""><br class=""></div><div class="">But it doesn't in practice work. The documentation for the (target: action:) initializer states:</div></div><div class=""><div class=""><br class=""></div><div class="">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 class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Or I did something wrong?</div><div class=""><br class=""></div><div class=""><br class=""></div></div></div></div><div class="gmail_extra"><div class=""><div class="h5"><br class=""><div class="gmail_quote">On Sun, Jun 4, 2017 at 1:55 AM, Nate Birkholz <span dir="ltr" class=""><<a href="mailto:nbirkholz@gmail.com" target="_blank" class="">nbirkholz@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Ah, I didn'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's too bad, closure-based gesture recognizers would be snazzy and swifty and I'd love to see them as part of UIKit. <div class=""><br class=""></div><div class="">I could write my own custom implementations of subclassed UIKit.UIGestureRecognizerSubcl<wbr class="">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 class=""><div class="gmail_quote">On Sun, Jun 4, 2017 at 1:21 AM, Nate Birkholz <span dir="ltr" class=""><<a href="mailto:nbirkholz@gmail.com" target="_blank" class="">nbirkholz@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class=""><div class="">I briefly considered something like this but didn't explore it. Elegant.<br class=""><br class="">Sent from my iPhone, please excuse brevity and errors</div><div class=""><br class="">On Jun 3, 2017, at 9:38 PM, Geordie Jay <<a href="mailto:geojay@gmail.com" target="_blank" class="">geojay@gmail.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">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'm writing this on my phone so forgive any syntax errors or accidental omissions:<br class=""><br class="">class TapGestureRecognizer: UITapGestureRecognizer {<br class=""> var onTap: (() -> Void)?<br class=""> init(onTap: (() -> Void)?) {<br class=""> self.onTap = onTap<br class=""> super.init(target: self, action: #selector(internalTapHandler))<br class=""> }<br class=""><br class=""> @objc private func internalTapHandler() {<br class=""> onTap?()<br class=""> }<br class="">}<br class=""><br class="">class Baz: Foo {<br class=""> init() {<br class=""> let tapRecognizer = TapGestureRecognizer(onTap: self.bar)<br class=""> }<br class="">}<br class=""><br class=""><br class="">Cheers,<br class="">Geordie<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sat 3. Jun 2017 at 16:53, Nate Birkholz via swift-users <<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">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 class=""><div class="gmail_quote">On Fri, Jun 2, 2017 at 9:58 PM, Zhao Xin <span dir="ltr" class=""><<a href="mailto:owenzx@gmail.com" target="_blank" class="">owenzx@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">I found two workarounds.</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">1.</div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Foo: </span><span style="font-variant-ligatures:no-common-ligatures" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> bar()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Base:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">@objc</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> bar() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">"bar"</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Baz: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Base</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures" class="">override</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures" class="">init</span><span style="font-variant-ligatures: no-common-ligatures;" class="">() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">super</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> tapRecognizer = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">UITapGestureRecognizer</span><span style="font-variant-ligatures:no-common-ligatures" class="">(target: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">#selector</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">2.</div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Foo: </span><span style="font-variant-ligatures:no-common-ligatures" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> bar()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> bar() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">"bar"</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Baz: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> tapRecognizer = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">UITapGestureRecognizer</span><span style="font-variant-ligatures:no-common-ligatures" class="">(target: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">, action: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">#selector</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">delegate</span><span style="font-variant-ligatures:no-common-ligatures" class="">))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">@objc</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> delegate() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">Zhao Xin</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sat, Jun 3, 2017 at 10:35 AM, Nate Birkholz via swift-users <span dir="ltr" class=""><<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">protocol Foo: class {<div class=""> func bar()<br class=""><div class=""><div class="">}</div><div class=""><br class=""></div><div class="">extension Foo {</div><div class=""> func bar() {</div><div class=""> print("bar")</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">class Baz: Foo {</div></div></div><div class=""> init() {</div><div class=""> let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(bar))</div><div class=""> }</div><div class=""><div class="">}</div><div class=""><br class=""></div><div class="">the #selector tells me: "Argument of '#selector' refers to instance method 'bar()' that is not exposed to Objective-C" and asks me to add @objc to the method definition. </div><div class=""><br class=""></div><div class="">Adding @objc to the method tells me: "@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes"</div><div class=""><br class=""></div><div class="">Adding @objc to the protocol doesn't fix it, just introduces new issues.</div><div class=""><br class=""></div><div class="">"dynamic" cannot be applied to a protocol, so cannot be used alternatively. </div><div class=""><br class=""></div><div class="">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'd like to use default implementations if possible to make my code more DRY.</div><div class=""><br class=""></div><div class="">Is there a roadmap/plan for swift-native selector dispatch?</div><div class=""><br class=""></div><div class="">Thanks. I look forward to the inevitable reply revealing the dumb thing I missed. :)</div><span class="m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888" class=""><span class="m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288HOEnZb"><font color="#888888" class=""><span class="m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288m_7008235823108254220HOEnZb"><font color="#888888" class=""><div class=""><div class=""><br class=""></div>-- <br class=""><div class="m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288m_7008235823108254220m_8246596659823059447gmail_signature">Nate Birkholz</div>
</div></font></span></font></span></font></span></div></div><span class="m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888" class=""><span class="m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288HOEnZb"><font color="#888888" class="">
<br class="">______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-users</a><br class="">
<br class=""></font></span></font></span></blockquote></div><span class="m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888" class=""><br class=""></font></span></div><span class="m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888" class="">
</font></span></blockquote></div><span class="m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888" class=""><br class=""><br clear="all" class=""><span class="m_6716881662020614998HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div>-- <br class=""><div class="m_6716881662020614998m_-2127668203321951367m_-4063239687484628030m_5017937476429152288gmail_signature" data-smartmail="gmail_signature">Nate Birkholz</div>
</font></span></font></span></div><span class="m_6716881662020614998HOEnZb"><font color="#888888" class=""><span class="m_6716881662020614998m_-2127668203321951367HOEnZb"><font color="#888888" class="">
______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-users</a><br class="">
</font></span></font></span></blockquote></div><span class="m_6716881662020614998HOEnZb"><font color="#888888" class="">
</font></span></div></blockquote></div></blockquote></div><span class="m_6716881662020614998HOEnZb"><font color="#888888" class=""><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="m_6716881662020614998m_-2127668203321951367gmail_signature" data-smartmail="gmail_signature">Nate Birkholz</div>
</font></span></div>
</blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div></div></div><span class="HOEnZb"><font color="#888888" class="">-- <br class=""><div class="m_6716881662020614998gmail_signature" data-smartmail="gmail_signature">Nate Birkholz</div>
</font></span></div>
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>