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?
    – ytbryan
    Oct 7, 2014 at 12:30
  • @ytbryan I'm using the same Xcode version as you.
    – thomas.g
    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.
    – ytbryan
    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
    – thomas.g
    Oct 7, 2014 at 12:35
  • yeah. sounds like a right choice.
    – ytbryan
    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

4
  • 1
    Ok, so I'm not the only one :-) thank you guys, Swift and Xcode bugs are driving me crazy...
    – thomas.g
    Oct 7, 2014 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 7, 2014 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 7, 2014 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 7, 2014 at 12:46

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.