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
But arrays in Swift are dynamic: you can grow them. And it is a lot less clear whether Swift is efficient in this case.
If you create an array, a set, or a dictionary, and assign it to a variable, the collection that's created will be mutable. This means that you can change (or mutate) the collection after it's created by adding, removing, or changing items in the collection.
Array's have fixed types, just like any other variable in Swift. That means that every element in an array has the same type, that cannot be changed once set. All array elements must have the same type, too. In the above examples, every item has a fixed type: String, Int and Double.
Difference between an Array and Set in SwiftArray is faster than set in terms of initialization.
I can reproduce this result reliably in Xcode 6.0.1:
But not in Xcode 6.1 GM:
Looks like it's a bug that got fixed.
As a temporary workaround, this works in Xcode 6.0.1:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With