<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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"><span class=""><br>
> In fact why not just use the generics syntax with protocols ? Anybody implementing a "Generic" Protocol has to specify the types.<br>
</span>That's a simple solution, but inconvenient:<br>
One use case for placeholders (I don't use the official name here to propagate an alternative ;-) is when you have a types that depend on a parameter.<br>
I'm to lazy to look up a real example, but Array<Int> is naturally associated with an enumerator for Int — and it is no fun to be forced to include such relationships all over the place.</blockquote></div><br>So in my example with placeholders.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div style="font-size:12.8px">class GenericCollection<Type>: Collection<Key: Type, Value: Type> </div><div style="font-size:12.8px">{</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">}</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Has already specified the type of the placeholder :) so subclasses don't need to specify it. <span style="font-size:12.8px">In this example the Key and Value type placeholders are bound to whatever the Type is.</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">So in these examples</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">let items: </span><span style="font-size:12.8px">GenericCollection<Int></span><span style="font-size:12.8px"> = </span><span style="font-size:12.8px">GenericCollection()</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">or</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">let items: [Int] = []</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">the Key and Value type placeholders would be Ints :) since the generic type is an Int.</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div></div>