<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="">At one point we talked about co-opting "Any" for this purpose, i.e. replacing the "protocol&lt;…&gt;" syntax with "Any&lt;…&gt;". Like a concrete type, you're not required to provide arguments, so "Any" by itself doesn't change meaning. Like an inheritance clause, the compiler would check if you ever had more than one class there.</div><div class=""><br class=""></div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 4, 2015, at 23:38 , Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">I think this is a very useful feature of Obj-C that I've missed several times while writing Swift code.</div><div class=""><br class=""></div>However, calling it "TheClass&lt;Protocol1, Protocol2&gt;" directly conflicts with the syntax for specifying generic type parameters.<div class=""><br class=""></div><div class="">If we use "protocol&lt;TheClass, Protocol1, Protocol2&gt;" for this case, then `protocol` stops making sense. Maybe the keyword `class` could be allowed instead, like "class&lt;TheClass, Protocol1, Protocol2&gt;".</div><div class=""><br class=""></div><div class="">Or, it might work to omit the keyword entirely, leaving only the angle brackets:</div><div class=""><br class=""></div><div class=""><span style="font-family: monospace, monospace;" class="">class C {</span></div><div class=""><span style="font-family: monospace, monospace;" class="">&nbsp; &nbsp; weak var delegate: &lt;UIViewController, UICollectionViewDelegate&gt;?</span><br class=""></div><div class=""><span style="font-family: monospace, monospace;" class="">}</span></div><div class=""><span style="font-family: monospace, monospace;" class=""><br class=""></span></div><div class=""><font face="monospace, monospace" class="">if let task = object as? &lt;NSManagedObject, Task&gt; {</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp; task.coreDataRelatedFunction()</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp; task.taskRelatedFunction()</font></div><div class=""><font face="monospace, monospace" class="">}<br class=""></font><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class="">Jacob Bandes-Storch<br class=""></div></div></div></div><br class=""><div class="gmail_quote">On Fri, Dec 4, 2015 at 3:07 PM, Daniel Muhra<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:daniel.muhra@gmail.com" target="_blank" class="">daniel.muhra@gmail.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class="">Currently it doesn’t seem possible to define a property or variable of a specific class that also implements one or more protocols.</div><div class="">Take as an example the following definition from Objective C:</div><div class=""><br class=""></div><div class="">NSManagedObject&lt;NSCoding, Task&gt;* someObject;</div><div class=""><br class=""></div><div class="">To my knowledge, currently it is only possible to define multiple protocols only:</div><div class=""><br class=""></div><div class="">var object : protocol&lt;NSCoding, Task&gt;</div><div class=""><br class=""></div><div class="">However, given the first example, sometimes it is not possible to restrict to protocols only. This becomes especially cumbersome, if you would need to cast down to such a construct within a single method and perform several steps which would require all those type information:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">func</span><span class="Apple-converted-space">&nbsp;</span>doSomething(object:<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(112, 61, 170);" class="">AnyObject</span>) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">if</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">let</span><span class="Apple-converted-space">&nbsp;</span>managedObject = object<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">as</span>?<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(112, 61, 170);" class="">NSManagedObject</span><span class="Apple-converted-space">&nbsp;</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span>// Do core data related stuff</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">if</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">let</span><span class="Apple-converted-space">&nbsp;</span>task = object<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">as</span>?<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Task</span><span class="Apple-converted-space">&nbsp;</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span>// Do task related stuff</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>} &nbsp;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">In this case you now have managedObject and task though you operate on the same object. Also it is not (easily) possible to interleave actions of those two.</div><div class=""><br class=""></div><div class="">My first idea here would be to introduce an Objective C like style of type naming. This also has the benefit, that it is perfectly clear, whether a type name refers to a class or a protocol (without first having to check it).</div><div class="">The downside, of course, is that protocol type variables would become something like Any&lt;MyProtocol&gt;</div><div class=""><br class=""></div><div class="">Any other ideas are welcome, but the initial problem still stands and should be addressed.</div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=P-2BsYbBZHRBuLDBJaL4DIKDNfkkjpROowTyRAObV11qzACF9YRuxumYAeOcjMBMERlHbU2myf8ioaOsp-2BPToMuh895Axgj6LtwERWSlpL9aKsSMR1lHFMskcS5-2BhdmkamiQ8tBD07utFDtkrluR6H7OdaAICxJuPdmKgz8n6omnxYTdXv8RdTJVQEgc-2F2p-2F-2FGUi0XIRRWm8EroRMTRt4o-2FKAhh-2FsSuNkImzT5nJoaGNo-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class=""></blockquote></div><br class=""></div></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZEz4qHYnXhPr3bBPu-2FxP4tN3HfWKL-2FtJpqkQ0gkOVSCt5hBvmRbG-2FMi9GaCycvW3MElL49wMpA7nfPcAFW27bC6iMg-2FzffaHNDaWYDBmsXK7HscP81WRqSIG7nEnqlaDkFVUDZR3vbE-2B-2BV9DoBEi9jaNSTfwp6ZKwVST84o7ifG6OoO-2BD9l2mXJd-2BZXhhuk2qOJez9RghHeOnEg7FwCXbf2reEnh4qlPk-2F7EZlXq0nc-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>