title: How to pass any class or struct as a parameter in function?
body: <p>I am using Swift 4.1 and Xcode 9.3. I want to make a function which takes any Class or Struct as parameter.</p>
  
  <p>Code example:</p>
  
  <pre><code>func cast&lt;T&gt;(a: Any, b: T) {
  
      let c = a as? b
  
      if let c = c {
          print("Good: \(c)")
      } else {
          print("Bad")
      }
  
  }
  
  cast(a: 1, b: Int.self)
  </code></pre>
  
  <p>But it has error in this line:</p>
  
  <pre><code>let c = a as? b
  </code></pre>
  
  <p>Error: <code>Use of undeclared type 'b'</code></p>
  
  <p>I want to call function cast like this: <code>cast(a: 1, b: Int)</code> or like this: <code>cast(a: "a", b: String)</code>
  The main idea to pass class or struct as parameter in generics functions correctly, how to do this?
  Thank you very much for any help or advice!</p>