<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Then no, this wouldn’t be possible unless you could somehow express something like:</p>

<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px; color:black" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7"><span style="color: #888888">// Cribbing some C++-style syntax here</span>
<span style="color: #008800; font-weight: bold">enum</span> <span style="color: #BB0066; font-weight: bold">OneOf</span>&lt;T<span style="color: #FF0000; background-color: #FFAAAA">…</span><span style="color: #333333">&gt;</span> : Codable <span style="color: #008800; font-weight: bold">where</span> T<span style="color: #FF0000; background-color: #FFAAAA">…</span> : Codable {
    cases t<span style="color: #FF0000; background-color: #FFAAAA">…</span>(T<span style="color: #FF0000; background-color: #FFAAAA">…</span>)
}
</code></pre>



<p dir="auto">where someone would be able to express to you that they want to store a <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">OneOf&lt;Int, String, Double, MyFoo&gt;</code> through your enum, or something like that.</p>

<p dir="auto">You could do that in a non-extensible way with something like</p>

<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px; color:black" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7"><span style="color: #008800; font-weight: bold">enum</span> <span style="color: #BB0066; font-weight: bold">MyEnum</span>&lt;T&gt; : Codable <span style="color: #888888">/* where T : Codable */</span> <span style="color: #888888">/* &lt;- when conditional conformance arrives */</span> {
    <span style="color: #008800; font-weight: bold">case</span> int(<span style="color: #007020">Int</span>)
    <span style="color: #008800; font-weight: bold">case</span> string(<span style="color: #007020">String</span>)
    <span style="color: #008800; font-weight: bold">case</span> custom(T)
    <span style="color: #008800; font-weight: bold">case</span> list([MyEnum&lt;T&gt;])
    <span style="color: #008800; font-weight: bold">case</span> dictionary([<span style="color: #007020">String</span> : MyEnum&lt;T&gt;])
}
</code></pre>



<p dir="auto">but that’s not truly heterogeneous without extending with more generic types.</p>

<p dir="auto">If you don’t know the type you need to decode, then you won’t be able to do this unless the encoder/decoder supports somehow mapping the type to and from data in the payload.</p>

<p dir="auto">On 19 Oct 2017, at 12:52, David Baraff wrote:</p>

<blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px">
<p dir="auto">An even bigger “no can’t do that”: the enum would be in some base/low-level library, and thus can’t know about new types that exist in higher-up libraries.</p>
</blockquote>
</div>
</div>
</body>
</html>