What is a good alternative for static stored properties of generic types in swift? : <p>Since static stored properties are not (yet) supported for generic types in swift, I wonder what is a good alternative.</p>

<p>My specific use-case is that I want to build an ORM in swift. I have an <code>Entity</code> protocol which has an associatedtype for the primary key, since some entities will have an integer as their <code>id</code> and some will have a string etc. So that makes the <code>Entity</code> protocol generic.</p>

<p>Now I also have an <code>EntityCollection&lt;T: Entity&gt;</code> type, which manages collections of entities and as you can see it is also generic. The goal of <code>EntityCollection</code> is that it lets you use collections of entities as if they were normal arrays without having to be aware that there's a database behind it. <code>EntityCollection</code> will take care of querying and caching and being as optimized as possible.</p>

<p>I wanted to use static properties on the <code>EntityCollection</code> to store all the entities that have already been fetched from the database. So that if two separate instances of <code>EntityCollection</code> want to fetch the same entity from the database, the database will be queried only once.</p>

<p>Do you guys have any idea how else I could achieve that?</p>
