6

In Swift arrays have a special behaviour, but why here does arr1 contain two times "item 1" whereas arr2 contains it only once ?

What does defining arr1 as an instance variable change here (versus defining arr2 as a local variable) ?

Update: I'm using Xcode 6.0.1

enter image description here

thomas.g
  • 3,894
  • 3
  • 29
  • 36

1 Answers1

2

I can reproduce this result reliably in Xcode 6.0.1:

Xcode 6.0.1

But not in Xcode 6.1 GM:

Xcode 6.1

Looks like it's a bug that got fixed.

As a temporary workaround, this works in Xcode 6.0.1:

Workaround

Greg
  • 9,068
  • 6
  • 49
  • 91
  • 1
    Ok, so I'm not the only one :-) thank you guys, Swift and Xcode bugs are driving me crazy... – thomas.g Oct 07 '14 at 12:33
  • @thomas.g I gave up trying to use it around the time I tried to use objc APIs that needed method selectors, right after giving up on the impossible to decipher initialiser overriding rules. Personally, I don't think it's worth the pain of the constant bugs, unnecessary and nonsensical restrictions, and sometimes unwieldy/unclear syntax, just to get the ~1.5x performance improvement over objc, which gives you the full power of performance of C whenever you need it. – Greg Oct 07 '14 at 12:37
  • I'm starting to feel the same. But soon I have to give a training on iOS development with Swift so no choice... but I must say that I'm a bit anxious ;-) At least for me Xcode / Playgrounds seems to crash less often since it isn't a beta anymore... – thomas.g Oct 07 '14 at 12:41
  • @thomas.g it seems ok until you try to do something serious in it; I tried to write a today widget for my timetable app in it, and it felt like it was actively putting up barriers before my to prevent me from writing a program that did what I wanted. Gave up and rewrote in objc, ~2x shorter code, and actually works. – Greg Oct 07 '14 at 12:46