title: In Swift how can I filter an array of objects conforming to a protocol by their class?
body: <p>I have a protocol, 'VariousThings', and two classes which conform to it, 'ThingType1' and 'ThingType2'. I've put some objects of these two types of classes into an array containing 'VariousThings'. I now want to just take all the objects out of that array that are of class type 'ThingType2' for example. How can I do this? </p>
  
  <p>Here's what I have so far: </p>
  
  <pre><code>protocol VariousThings: class {
  
  }
  
  class ThingType1: VariousThings {
  
  }
  
  class ThingType2: VariousThings {
  
  }
  
  
  let array: [VariousThings] = [ThingType1(), ThingType2()]
  
  
  func itemsMatchingType(type: VariousThings.Type) -&gt; [VariousThings] {
      return array.filter { variousThing in
          return (variousThing.self === type)
      }
  }
  
  
  let justThingTypes1: [VariousThings] = itemsMatchingType(ThingType1)
  </code></pre>