<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Are you sure that your problem is about generics on lambdas? Seems to me that you wouldn't need generic lambdas if you could solve your initial problem in a different way.</div><div class=""><br class=""></div>You can use Self in protocols, which refers to the implementing type:<div class=""><br class=""></div><div class=""><div class=""></div><blockquote type="cite" class=""><div class="">protocol MyProtocol {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var protocolControllerCallback: Self -&gt; Void { get }</div><div class="">}</div><div class=""><br class=""></div><div class="">class MyController: MyProtocol {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var protocolControllerCallback: MyController -&gt; Void</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init() {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>protocolControllerCallback = { cnt in return }</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class="">}</div></blockquote><div class=""><br class=""></div>That doesn't work right now because Swift will complain that the class must be `final` for reasons that sound bogus to me: "it uses 'Self' in a non-parameter, non-result type position". I don't know if there's a technical reason that it can't be in a closure parameter. Still seems to get you closer to what you want.</div><div class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>

<br class=""><div><blockquote type="cite" class=""><div class="">Le 15 janv. 2016 à 05:07:06, Spencer Kohan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">New here, hope I'm doing this right.
<div class=""><br class=""></div><div class="">I recently found a use case which does not appear to be covered by the swift language: it appears that there's no way to declare a closure type with generic arguments.</div><div class=""><br class=""></div><div class="">For example, what if I'm building an iOS app, and I want to define a closure which operates on UIViewControllers which implement a particular protocol?<br class=""></div><div class=""><br class=""></div><div class="">In ObjectiveC, this would be possible with the following syntax:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; typedef void (^MyBlockType)(UIViewController&lt;MyProtocol&gt;)</div><div class=""><br class=""></div><div class="">In Swift you can do this in the context of a function, class or struct:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; func myFunction&lt;T: UIViewController where T:MyProtocol&gt;() {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; let x : (T) -&gt; () = { generic in</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;....</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">But what if you want to declare such a closure as a variable within the protocol it's referring to?</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; protocol MyProtocol {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; var protocolControllerCallback : (protocolController : ???? )-&gt;()</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">It seems like Associated Types are the intended tool for this job, so you could have something like:</div><div class=""><br class="">&nbsp; &nbsp; protocol MyProtocol {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; typealias ProtocolObservingController</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; var protocolControllerCallback : (protocolController :&nbsp;ProtocolObservingController&nbsp;)-&gt;() {get set}</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; class MyController : UIViewController, MyProtocol {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; typealias ProtocolObservingController = MyController</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; ...</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">But this doesn't quite solve the problem: we still can't have a closure defined in this protocol which can operate on *any* implementations of the protocol.&nbsp; For instance, what if we wanted to pass a closure between two different implementations?</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; class MyChildController : UIViewController, MyProtocol {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; typealias ProtocolObservingController = MyChildController</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; ...</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; &nbsp; class MyParentController : UIViewController, MyProtocol {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; typealias ProtocolObservingController = MyParentController</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; ...</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; func createChildController() -&gt; MyControllerChild {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let child = MyChildController()</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child.protocolControllerCallback = self.protocolControllerCallback</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; }</div></div><div class=""><br class=""></div><div class="">It doesn't work because the types of protocolControllerCallback are inconsistent between the two classes.</div><div class=""><br class=""></div><div class="">This feels like a hole in the language.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=iRI3beHTe3UxYAHTlV3lA38zIPfHMhyuRzgTmGKV6k4aCoAQZUIFePb7DSEP1BFSBFa9noVtcNSceUSF5Efg5XbsIaCciTuKiWCR55Hnalx0GWqOfNtwhoB5ANOQbZbR9xzfrar-2BDhMfMxXSUDFqwGr6ES6Ffsmjh-2FleexHeQ9JVGElR6plMfgPvpcnUNJ8vom76Oi5ThLNqg9pOb7LRIZd-2Bjo2rVbTKO1VIq4wHB9I-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>