title: Remove object from Array passing an instance of protocol
body: <p>I have a protocol called <code>IdeaListener</code>, and an array of elements which extends this protocol.</p>
  
  <pre><code>private var ideaListeners: [IdeaListener]
  </code></pre>
  
  <p>I want to create an extension in order to remove an object from the array given an instance of <code>IdeaProtocol</code>.</p>
  
  <pre><code>var myInstanceOfIdeaListener: IdeaListener
  ...
  ideaListeners.removeObject(myInstanceOfIdeaListener)
  </code></pre>
  
  <p>I have found many solutions on the web but none of them were able to accept a protocol as parameter of the <code>removeObject</code> function.
  In order to accomplish this, I wrote this extension:</p>
  
  <pre><code>extension Array {
  
     mutating func removeObject(object: AnyObject) -&gt; Element? {
  
      for (index, objectToCompare) in self.enumerate() {
          if let to = objectToCompare as? AnyObject where to == object {
              return removeAtIndex(index)
          }
      }
      return nil
    }
  }
  </code></pre>
  
  <p>But the compiler says </p>
  
  <blockquote>
    <p>Binary operator '==' cannot be applied to two 'AnyObject' operands.</p>
  </blockquote>
  
  <p>Why I cannot use == for comparing two <code>AnyObject</code>? How would you check if the array contains <code>object</code>?</p>
  
  <p>Moreover, I want to improve this function, adding a type check at the beginning, in order to check if the type of <code>object</code> is actually the type of the elements in the array. I am not sure how to code this concept though. Something like this:</p>
  
  <pre><code>guard object is /*type of elements in array*/ else {
       return nil
  }
  </code></pre>
  
  <p>How can I get the type of the elements in the array?</p>