Arrays in Swift are value types. This means that it is datacopied when passing to your method exchange, but you are trying to modify the copy to affect the original version. Instead, you should do one of two things:
1. Define dataas a parameter inout:
func exchange<T>(inout data:[T], i:Int, j:Int)
Then, calling it, you must add &before the call:
var myArray = ["first", "second"]
exchange(&myArray, 0, 1)
2. ()
func exchange<T>(data:[T], i:Int, j:Int) -> [T]
{
var newData = data
newData[i] = data[j]
newData[j] = data[i]
return newData
}
in-out, in-out . , . , exchange ? , Apple , in-out subverts. , , , Swift. , ( ).