<div dir="ltr">It will work if you change the enum declaration to:<div><br></div><div><font face="monospace, monospace">enum ElementNode&lt;T&gt;</font><br></div><div><br></div><div>In other words, let the enum hold arbitrary unconstrained associated types, and then make your APIs utilize instances of the enum with the associated type constrained to a protocol.<br></div><div><br></div><div>The specific example you provide is essentially equivalent to:</div><div><br></div><div><font face="monospace, monospace">var childElements = [Element?]()</font><br></div><div><br></div><div>Nevin</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 28, 2016 at 6:41 PM, Brandon Knope via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I don’t understand why this is a problem<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#bb2ca2">protocol</span><span style="font-variant-ligatures:no-common-ligatures"> Element {</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_3186968394912350862webkit-block-placeholder"></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#bb2ca2">enum</span><span style="font-variant-ligatures:no-common-ligatures"> ElementNode&lt;T: Element&gt; {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#bb2ca2">case</span><span style="font-variant-ligatures:no-common-ligatures"> element(</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187">T</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#bb2ca2">case</span><span style="font-variant-ligatures:no-common-ligatures"> empty</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#bb2ca2">var</span><span style="font-variant-ligatures:no-common-ligatures"> childElements = [</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187">ElementNode</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187">Element</span><span style="font-variant-ligatures:no-common-ligatures">&gt;]()</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">I need to represent an array of my nodes that could be multiple kinds of elements</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">Is there a workaround?</span></div><span class="HOEnZb"><font color="#888888"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">Brandon</span></div></font></span></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>