<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Oh that's clever. I like that. It doesn't have a big impact on the language and it makes reasonable sense when read. We could also establish convention (possibly backed up by warnings) that says that if Any<...> contains a class, the class name must come first.<br></div>
<div> </div>
<div>-Kevin Ballard<br></div>
<div> </div>
<div>On Tue, Dec 15, 2015, at 06:27 PM, Jordan Rose via swift-evolution wrote:<br></div>
<blockquote type="cite"><div>At one point we talked about co-opting "Any" for this purpose, i.e. replacing the "protocol<…>" syntax with "Any<…>". 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.<br></div>
<div> </div>
<div>Jordan<br></div>
<div> </div>
<div><blockquote type="cite"><div>On Dec 4, 2015, at 23:38 , Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com">jtbandes@gmail.com</a>> wrote:<br></div>
<div> </div>
<div><div 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;" dir="ltr"><div>I think this is a very useful feature of Obj-C that I've missed several times while writing Swift code.<br></div>
<div> </div>
<div>However, calling it "TheClass<Protocol1, Protocol2>" directly conflicts with the syntax for specifying generic type parameters.<br></div>
<div> </div>
<div>If we use "protocol<TheClass, Protocol1, Protocol2>" for this case, then `protocol` stops making sense. Maybe the keyword `class` could be allowed instead, like "class<TheClass, Protocol1, Protocol2>".<br></div>
<div> </div>
<div>Or, it might work to omit the keyword entirely, leaving only the angle brackets:<br></div>
<div> </div>
<div><span class="font" style="font-family:monospace, monospace">class C {</span><br></div>
<div><span class="font" style="font-family:monospace, monospace"> weak var delegate: <UIViewController, UICollectionViewDelegate>?</span><br></div>
<div><span class="font" style="font-family:monospace, monospace">}</span><br></div>
<div> </div>
<div><span class="font" style="font-family:monospace, ' monospace'">if let task = object as? <NSManagedObject, Task> {</span><br></div>
<div><span class="font" style="font-family:monospace, ' monospace'"> task.coreDataRelatedFunction()</span><br></div>
<div><span class="font" style="font-family:monospace, ' monospace'"> task.taskRelatedFunction()</span><br></div>
<div><div><span class="font" style="font-family:monospace, ' monospace'">}<br></span></div>
<div><div> </div>
<div><div><div dir="ltr"><div>Jacob Bandes-Storch<br></div>
</div>
</div>
</div>
<div> </div>
<div><div>On Fri, Dec 4, 2015 at 3:07 PM, Daniel Muhra<span></span><span dir="ltr"><<a href="mailto:daniel.muhra@gmail.com">daniel.muhra@gmail.com</a>></span><span></span>wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left: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;"><div>Currently it doesn’t seem possible to define a property or variable of a specific class that also implements one or more protocols.<br></div>
<div>Take as an example the following definition from Objective C:<br></div>
<div> </div>
<div>NSManagedObject<NSCoding, Task>* someObject;<br></div>
<div> </div>
<div>To my knowledge, currently it is only possible to define multiple protocols only:<br></div>
<div> </div>
<div>var object : protocol<NSCoding, Task><br></div>
<div> </div>
<div>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:<br></div>
<div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;"> </div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span class="colour" style="color:rgb(187, 44, 162)">func</span><span></span>doSomething(object:<span></span><span class="colour" style="color:rgb(112, 61, 170)">AnyObject</span>) {<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span></span><span class="colour" style="color:rgb(187, 44, 162)">if</span><span></span><span class="colour" style="color:rgb(187, 44, 162)">let</span><span></span>managedObject = object<span></span><span class="colour" style="color:rgb(187, 44, 162)">as</span>?<span></span><span class="colour" style="color:rgb(112, 61, 170)">NSManagedObject</span><span></span>{<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0, 132, 0);"><span style=""><span></span></span>// Do core data related stuff<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span></span>}<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px;"> </div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span></span><span class="colour" style="color:rgb(187, 44, 162)">if</span><span></span><span class="colour" style="color:rgb(187, 44, 162)">let</span><span></span>task = object<span></span><span class="colour" style="color:rgb(187, 44, 162)">as</span>?<span></span><span class="colour" style="color:rgb(79, 129, 135)">Task</span><span></span>{<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0, 132, 0);"><span style=""><span></span></span>// Do task related stuff<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;"><span></span>} <br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;">}<br></div>
</div>
<div> </div>
<div>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.<br></div>
<div> </div>
<div>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).<br></div>
<div>The downside, of course, is that protocol type variables would become something like Any<MyProtocol><br></div>
<div> </div>
<div>Any other ideas are welcome, but the initial problem still stands and should be addressed.<br></div>
<div><img style="min-height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-right:0px !important;margin-bottom:0px !important;margin-left:0px !important;padding-top:0px !important;padding-right:0px !important;padding-bottom:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/fd56f32021fabb20ed3f7517094abddf036d06b177de7d04f288f7139de36e71/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d305d2232437952624a584252457c44424a416c4434494b444e466b6b6a60725f4f67745972514f42665131317a7143464939525578757d6951456f436a6d424d45425c684265523d697668396f616f43707d223240545f6d45786839353148776a663c4477754257535c607c49316b43735d42513c68464d437b6363553d223248646d6b616d696158347244403735747644447b627c65725638473f4461614943487a4570546d6b476a783e663f6d6e687954546856783254645a46515547636d223642307d22364d22364745596038594252575d6835427f625d445254743f6d22364b4148686d22364373557e4b694d6a74553e6a4f61674e4f6d23344/open"><br></div>
</div>
<div> </div>
<div>_______________________________________________<br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
<div> </div>
</blockquote></div>
<div> </div>
</div>
</div>
</div>
<div><img 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-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-right:0px !important;margin-bottom:0px !important;margin-left:0px !important;padding-top:0px !important;padding-right:0px !important;padding-bottom:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/c81ace139430653ffb1201803ab6d7457d69e6d80fc1bb5011b161ca2682c603/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3a554a743178495e6858605273326240557d2236487054347e433846675b4c4d2236447a40717b6150376b6f46535344753862467d6252674d22364d496937416349736677533d454c6c4439377d4071473e6660536146475237326346396d476d22364a766661684e4441675954424d63785b47384373605831375251735947473e654e617c61644b664655544a52533672654d22324d22324659344f624549693a616e4354566770763a5b4776535458343f67396667463f4f6f4d223244493c623d685a446d22324a585868657b62317f4a456a7932576868456f4e654767364773485266623275654e6864317c605b6d223647354a5c6851703e636d23344/open"><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"><span></span>_______________________________________________</span></span><br></div>
<div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">swift-evolution mailing list</span></span><br></div>
<div><a 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;" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a 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;" href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</blockquote></div>
<div> </div>
<div> <img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/a34bb4f2b4d206e1f95184c5793f7d9800e398b6e63a3e28501ea829d5231d33/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e455447423037463b6d4a407673655f486c6d6753695a66736460735a623b4943317d4972525a4346363930786256707a49557d653d684e45313e6d6c41456d453575394a555f677d67637463367358505667785e6567393249356c4675495633517662615c4a46525d4570716d2236435a6330305733684b463d4d22324470783c6474537f4f6442464a665249554d6844647a5a6f65675c63683879626a7c435a427745565a77396d667f4b4d22324d685d49557f405d68573a52563a64455e61665f4a423e476d23344d23344/open"><br></div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div> </div>
</body>
</html>