title: Passing and Casting Object Types in Swift
body: <pre><code>class TEST1 : NSObject  {
  
  var name : String?
  }
  class TEST2 : NSObject  {
  
  var name : String?
  }
  func compareObjects&lt;T&gt;(array1: [NSObject], array2: [NSObject], type:T.Type)  {
  
  for objectA in array1  {
      let x = objectA as! T
      for objectB in array2{
          let y = objectA as! T
          if x.name == y.name {
              print("found a match")
              }
          }
       }
  }
  </code></pre>
  
  <p>I don't think this is allowed.
  But if you all know a way to make it work it would be much appreciated. it'll save me a lot of duplicate code.</p>