title: Swift: how to return class type from function
body: <p>I know it is possible to pass class type to a function in swift:</p>
  
  <pre><code>func setGeneric&lt;T&gt;(type: T.Type){ }
  setGeneric(Int.self)
  </code></pre>
  
  <p>But how we can return type from function? Writing something like</p>
  
  <pre><code>func getGeneric&lt;T&gt;() -&gt; T.Type {
     return Int.self
  }
  </code></pre>
  
  <p>gives compiler error "Int is not identical to T". So is it possible to return type from a swift function?</p>
  
  <p><strong>Edit</strong><br>
  Some explanation. I have classes that are used for persistence (I'm using Realm) and I have classes that acts as wrappers around this classes. All wrappers inherits from <code>RealmClassWrapper</code> which needs to know what Realm class it actually wraps. So lets say I have this realm model:</p>
  
  <pre><code>class RealmTodo: RLMObject {
     dynamic var title = ""
  }
  </code></pre>
  
  <p>and my wrappers supper class looks like this:</p>
  
  <pre><code>class RealmClassWrapper {
     private let backingModel: RLMObject
     //...
     func backingModelType&lt;T&gt;() -&gt; T.Type{ fatalError("must be implemented") }
  }
  </code></pre>
  
  <p>and actual wrapper:</p>
  
  <pre><code>class Todo: RealmClassWrapper {
     //some other properties
     func backingModelType&lt;T&gt;() -&gt; T.Type{ return RealmTodo.self }
  }
  </code></pre>