I want to store a reference to an array element and modify the array element using the 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 was that first would return a reference to the array element. Instead, Swift returns a copy of the element, meaning the array element doesn't get modified.
Is there a way to store a reference to an array element using Swift arrays?