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

5
  • Yup. I got the same result in Xcode Version 6.0.1 (6A317) :| I got to say it's a bug? Commented Oct 7, 2014 at 12:30
  • @ytbryan I'm using the same Xcode version as you. Commented Oct 7, 2014 at 12:31
  • yah. Looks like your best bet is to make it a local variable. Referring to PartiallyInifinite answer. Or use the Xcode GM. Commented Oct 7, 2014 at 12:34
  • I guess I will use the 6.1 GM, I don't really find that the local variable trick is a good bet :-) Arrays or Classes or I don't know what seem broken, I'd rather use a working version Commented Oct 7, 2014 at 12:35
  • yeah. sounds like a right choice. Commented Oct 7, 2014 at 12:36

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Ok, so I'm not the only one :-) thank you guys, Swift and Xcode bugs are driving me crazy...
@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.
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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.