realm/realm-cocoa — pull request #1144 by mrh-is (2014-11-21 18:54:15+00:00)
Title: Make RLMResults always iterate over contents at start of iteration

Currently, `RLMResults` can silently change while you are iterating through it, if you change something about an object that makes it no longer fit the query. This causes the loop to only apply to every other object in the results (which is very confusing and difficult to debug).

This commit causes the array to always iterate through the objects that were in the results array at the start of the iteration, even if some of the objects leave the array in the meantime. After the iteration, the results array is the correct (possibly changed) value. It does perform slightly slower than the previous implementation, but I would rather this behavior and slightly slower performance.

**Warnings**: This implementation is still vulnerable to objects being changed in any way other than being removed. It is also vulnerable to the temporary array being released early, is noted in [Mike Ash's discussion of `NSFastEnumeration`](https://www.mikeash.com/pyblog/friday-qa-2010-04-16-implementing-fast-enumeration.html). (Neither of these vulnerabilities is new in this commit, just noting them for posterity.)