Fast array behavior

Swift arrays have a special behavior, but why does arr1 contain two times โ€œelement 1โ€, while arr2 contains it only once?

What defines arr1 as an instance variable here (as opposed to defining arr2 as a local variable)?

Update: I am using Xcode 6.0.1

enter image description here

+6
source share
1 answer

I can reliably reproduce this result in Xcode 6.0.1:

Xcode 6.0.1

But not in Xcode 6.1 GM:

Xcode 6.1

It seems that a bug has been fixed.

As a temporary workaround, this works in Xcode 6.0.1:

Workaround

+2
source

Source: https://habr.com/ru/post/976357/


All Articles