So what’s the real problem here? There are actually two problems that end up causing this issue:
- Arrays are structs and structs have value-type semantics. The entire metadata for the array, such as the startIndex, endIndex, and the array buffer pointer all get copied on assignment. This is ripe for bugs, as we have seen above.
- Lack of true immutable types.
Update (2014-06-21): Apple will be changing the array semantics.
Stay up-to-date by subscribing to the Comments RSS Feed for this post.