Refresh Swift arrays are too weird. I think it is more reliable to use NSMutableArrayinstead if necessary.
I understand that Swift usually passes an array by value, not by reference, but I need to be able to pass the link in code as follows:
var arr1 = [1, 2, 4]
var arr2 = [4, 6, 3]
var result = pickOne() ? arr1 : arr2
result[2] = 7
println(arr1)
println(arr2)
I want to dynamically select one of two arrays and make changes to this array. Both arrays have the same size and type of content, and I would only change the elements, not add or delete. How can I achieve this?
Edit: is there an answer instead instead NSMutableArray?
Just to clarify: pickOne()- this is a function that I already have, and based on the results of this function, I want to change the first or second array. Therefore, I do not need help in choosing what to choose. I need help on how to make changes (and there will be several) to this desired array without having to check which array to use for each modification.
I could do something like this:
if pickOne() {
} else {
}
if pickOne() {
} else {
}
if pickOne() {
} else {
}
But it gets old quickly.
Edit
So far, I have made some progress here.
var result = pickOne() ? UnsafeMutableBufferPointer(start: &arr1, count: arr1.count) : UnsafeMutableBufferPointer(start: &arr2, count: arr2.count)
, , "", , . , Unsafe - .