@bffmike Since Swift arrays are structs, *every* array is immutable, and never shared. Mutating *replaces* the old array with a new one.
Hey #swiftlang peeps: How do you create an var that holds an immutable Array? As in a var that you can assign different immutable Arrays to?
-
-
-
@bjhomer "If you create an array or a dictionary and assign it to a variable, the collection that is created will be mutable" -
@bffmike is this what you’re worried about? var x = [1,2,3] x += [4,5] foo.array = x foo.modifyArray() // oh no, my ‘x’ changed! -
@bjhomer I want var x: NSArray where the array itself can't have items added, removed, or changed, but where x can be changed -
@bffmike I need more words; I’ll write up a blog post. But in short, this is what Swift already gives you; just doesn’t look like it. -
@bjhomer does this clarify things? https://gist.github.com/8294f3226ddb9993f20f.git … -
@bffmike so would this be allowed in your ideal case? var x: Array = [1,2,3] var tmp = x tmp += [4,5] x = tmp -
@bjhomer the third line would not be allowed in my ideal case - Show more
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
Mike R. Manzano
BJ Homer