Wednesday, June 18, 2014

Swift Arrays

David Owens II:

So what’s the real problem here? There are actually two problems that end up causing this issue:

  1. 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.
  2. Lack of true immutable types.

Update (2014-06-21): Apple will be changing the array semantics.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment