<div dir="ltr"><div class="markdown-here-wrapper" style=""><blockquote style="margin:1.2em 0px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<p style="margin:0px 0px 1.2em!important">Consider what I said above, I feel like we should tackle this:</p>
<ul style="margin:1.2em 0px;padding-left:2em">
<li style="margin:0.5em 0px">drop <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">init(_ copy: Type<T>)</code> - to keep equality of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">Type<T></code> references</li>
</ul>
</blockquote>
<p style="margin:0px 0px 1.2em!important">Agreed.</p>
<blockquote style="margin:1.2em 0px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<ul style="margin:1.2em 0px;padding-left:2em">
<li style="margin:0.5em 0px">make all initializer internal and as exchange make <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">sharedInstance</code> public.</li>
</ul>
<p style="margin:0px 0px 1.2em!important">This would ensure that you will always get a reference from the type storage, and that there can only exist one for each (dynamic) metatype.</p>
</blockquote>
<p style="margin:0px 0px 1.2em!important">I have another idea:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// No uniqueness guarantee</span>
internal <span class="hljs-class"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">class</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">_Type</span><<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">T</span>> </span>{
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">var</span> _metatype: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Metatype</span><<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">T</span>>
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>()
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>(<span class="hljs-number" style="color:rgb(0,128,128)">_</span>: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">AnyMetatype</span>)
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>?<<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">U</span>>(casting: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Type</span><<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">U</span>>)
<span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// Instead of a global dictionary</span>
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">class</span> <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">var</span> sharedInstance: _Type<<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">T</span>>
}
<span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// Uniqueness guarantee</span>
public <span class="hljs-class"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">struct</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">Type</span><<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">T</span>> </span>{
internal <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">var</span> impl: _Type<<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">T</span>>
public <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>()
public <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>(<span class="hljs-number" style="color:rgb(0,128,128)">_</span>: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">AnyMetatype</span>)
public <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>?<<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">U</span>>(casting: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Type</span><<span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">U</span>>)
}
</code></pre>
<blockquote style="margin:1.2em 0px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<p style="margin:0px 0px 1.2em!important">I can’t foresee the future, so I’m wondering if the type may mutate somehow when reflections are added?</p>
</blockquote>
<p style="margin:0px 0px 1.2em!important">I don’t think so. If added at all, types should only be able to be created using some kind of builder:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> builder = <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">TypeBuilder</span>(name: <span class="hljs-string" style="color:rgb(221,17,68)">"Person"</span>, kind: .<span class="hljs-class"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">struct</span>)
<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">builder</span>.<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">addField</span>(<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">name</span>: "", <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">type</span>: <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">Int</span>.<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">self</span>)
//...
<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">let</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">typeRef</span> = <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">builder</span>.<span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">create</span>()</span>
</code></pre>
<div title="MDH:PGRpdiBjbGFzcz0iZ21haWxfZXh0cmEiPjxkaXYgY2xhc3M9ImdtYWlsX2V4dHJhIj4mZ3Q7Q29u
c2lkZXIgd2hhdCBJIHNhaWQgYWJvdmUsIEkgZmVlbCBsaWtlIHdlIHNob3VsZCB0YWNrbGUgdGhp
czo8L2Rpdj48ZGl2IGNsYXNzPSJnbWFpbF9leHRyYSI+Jmd0OzwvZGl2PjxkaXYgY2xhc3M9Imdt
YWls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