title: Removing a specific object from an array in Swift 4
body: <p>I am trying to remove a specific Event object (my own class) from an array hold Event objects. This is my declaration of the array.</p>
  
  <pre><code>private var positiveEvents : [Event] = []
  </code></pre>
  
  <p>Now, here is what how I am trying to remove the Event object from the array. This method (disposeOfflineEvents) is called every 30 seconds, so positiveEvents might have some elements or none at all.</p>
  
  <pre><code>func disposeOfflineEvents() {
      for event in positiveEvents {
          if !event.ongoing {
              positiveEvents.remove(at:  positiveEvents.index(where: { $0 === event })!)
              print("! - Disposing of an event!")
          }
      }
  }
  </code></pre>
  
  <p>I saw <a href="https://stackoverflow.com/questions/41255494/remove-specific-object-from-array-in-swift-3">this</a> question, but I am using Swift 4, so I don't have the index(of: Event) method. The problem with my current solution is that I occasionally get an error when using "===" for checking equality of objects:</p>
  
  <p><a href="https://i.stack.imgur.com/xkpyf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xkpyf.png" alt="enter image description here"></a></p>
  
  <p>Is there any better way of doing this?</p>