0

I am trying to follow along with the playground video on the WWDC page, but for some reason I am getting this error now. I switch to beta 3 of Xcode 6 and I noticed they changed some stuff, such as array syntax but why can't by Type T work? enter image description here

I'm assuming something changed from the first beta to the third with this that I am not aware of.

domshyra
  • 933
  • 3
  • 11
  • 28

1 Answers1

1

The error message is rather cryptic and doesn't really tell you what the problem is.

In this case, the data argument needs to be an inout parameter, since you are modifying it and expect the changes to be available outside the function.

You should change your function to:

func exchange<T>(inout data: [T], i: Int, j: Int) {
    let temp = data[i]
    data[i] = data[j]
    data[j] = temp
}

And when calling it, prepend the data argument with &.

exchange(&someData, someInt, anotherInt)
Cezar
  • 55,636
  • 19
  • 86
  • 87