swift - How to store a reference to an array element? -
i want store reference array element , modify array element using reference.
example code:
var myarray : [string] = ["foo"] var element = myarray.first! element.append("bar") print(myarray.first!) expected output:
> foobar actual output:
> foo my expectation first return reference array element. instead, swift returns copy of element, meaning array element doesn't modified.
is there way store reference array element using swift arrays?
swift's string value type, returns copy not reference, if want reference should use nsstring not string.
Comments
Post a Comment