Swift generics: return type based on parameter type
<p>Say I have a collection of objects inheriting from a common superclass (this is preferable to protocols in this case):</p>

<pre><code>class ObjectSuperClass {
    type: ObjectType
}
class ObjectClass1: ObjectSuperClass {
    type = .Type1
}
class ObjectClass2: ObjectSuperClass {
    type = .Type2
}
</code></pre>

<p>I'm looking to create a generic search function like this:</p>

<pre><code>func objectsOfType&lt;T: ObjectSuperClass&gt;(T.class, otherFilter: Any?) -&gt; [T]
</code></pre>

<p>Which could be used to search for a given sub-type, returning a more specific array of results:</p>

<pre><code>let result = objectsOfType(ObjectClass2.class, otherFilter: nil) -&gt; [ObjectClass2]
(pseudo-swift)
</code></pre>

<hr>

<p>I feel like this is somewhere generics could help, but cannot see where constraints should be placed. Is it possible?</p>