Remove element from collection during iteration with forEach : <p>Recently, I wrote this code without thinking about it very much:</p>

<pre><code>myObject.myCollection.forEach { myObject.removeItem($0) }
</code></pre>

<p>where <code>myObject.removeItem(_)</code> removes an item from <code>myObject.myCollection</code>.</p>

<p>Looking at the code now, I am puzzled as to why this even works - shouldn't I get an exception along the lines of <code>Collection was mutated while being enumerated</code>?
The same code even works when using a regular for-in loop!</p>

<p>Is this expected behaviour or am I 'lucky' that it isn't crashing?</p>
